symfony - How to force the underlying form object to overtake the parent entity for its relation? -


i have 1 master entity , second one.

lets have map , map has points coordinates.

i want able add dynamicaly new records points i've choosen collection type of form type.

i have correct form type second entity. ok, except new added points not persisted master entity. how can tell form overtake parent entity , set appropriate setter?

$builder->add('routepoints', 'collection', ['required' => false,'label' => '','attr'=>['class'=>'route-point'],'by_reference'=> true, 'type' => new mapcoordinateadmintype(), 'allow_add' => true, 'delete_empty' => true, 'allow_delete' => true, 'translation_domain' => 'maps']); 

master entity

/**  * @var array  * @orm\onetomany(targetentity="adn\custombundle\entity\mapcoordinate", cascade={"persist","remove"}, mappedby="map")  * @orm\joincolumn(ondelete="cascade",name="route_points",nullable=true, referencedcolumnname="map")  */ protected $routepoints; 

points entity

/**  * @orm\manytoone(inversedby="routepoints", targetentity="adn\custombundle\entity\cyclemap")  * @orm\joincolumn(name="map",referencedcolumnname="id")  */ protected $map; 

your second entity instances not persisted because belong inverse side of bidirectional relationship. can find out more on doctrine documentation.

in order solve problem, need update owning side well. this, one-line change required in master entity:

<?php /** master entity */ use adn\custombundle\entity\mapcoordinate;  class cyclemap {     // ...      public function addroutepoint(mapcoordinate $routepoint)     {          // magical line          $routepoint->setmap($this);           $this->routepoints[] = $routepoint;           return $this;     } } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -