Details
Description
Dear developers,
I'm not sure if i extend entities in right way but i found different behaviour in extended entity which won't process add in @ManyToMany association.
My class are defined like this:
/** * @Entity * @HasLifecycleCallbacks * @InheritanceType("JOINED") * @DiscriminatorColumn(name="discr", type="string") * @DiscriminatorMap({"guest" = "Shop_Data_Entity_Guest", "customer" = "Shop_Data_Entity_Customer"}) */ class Shop_Data_Entity_Guest extends Shop_Data_Entity_Abstract { public function __construct() { /* call parent construct with all parameters */ call_user_func_array(array("parent","__construct"),func_get_args()); } } /** * @Entity * @HasLifecycleCallbacks */ class Shop_Data_Entity_Customer extends Shop_Data_Entity_Guest { /** * @ManyToMany(targetEntity="Shop_Data_Entity_Contact", cascade={"persist","remove"} ) * @JoinTable(name="Shop_Data_Entity_Customer__homes", * joinColumns={@JoinColumn(name="customer_id", referencedColumnName="id", onDelete="cascade" )}, * inverseJoinColumns={@JoinColumn(name="contact_id", referencedColumnName="id", onDelete="cascade" )} * ) */ public $homes; public function __construct() { /* call parent construct with all parameters */ call_user_func_array(array("parent","__construct"),func_get_args()); $this->homes = new Shop_Data_Collection_Standard(); // this class only extends ArrayCollection } }
When i fire this code:
$q = $em->createQuery("select c from Shop_Data_Entity_Customer c"); $q->setMaxResults(1); $customers = $q->getResult(); $contact = new Shop_Data_Entity_Contact(); $customers[0]->home->add($contact); $em->flush();
There's no change in database.
When i change definition od Guest class like this:
/** @MappedSuperclass */ class Shop_Data_Entity_Guest extends Shop_Data_Entity_Abstract { public function __construct() { /* call parent construct with all parameters */ call_user_func_array(array("parent","__construct"),func_get_args()); } }
It start work and every firing of my code add one contact and association to my database. It causes problem only when owning entity is quered from database at first.
I tried to debug by myself and i found that on line 411 in UnitOfWork.php is on flush in first example $class->associationMappings == null. When i change Shop_Data_Entity_Guest to /** @MappedSuperclass */ i can find $class->associationMappings on same line with some elements.
Hope it help to fix it
Andy