Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /** @Entity */
- class First
- {
- /** @OneToMany(targetEntity="Second", mappedBy="parent") */
- protected $secondList;
- // access methods here
- public function __construct()
- {
- $this->secondList = new ArrayCollection();
- }
- }
- /** @Entity */
- class Second
- {
- /**
- * @ManyToOne(targetEntity="First", inversedBy="secondList")
- * @JoinColumn(name="First_id", referencedColumnName="Id")
- */
- protected $parent;
- }
- $first = new Second();
- $second = new First();
- $first->getSecond()->add($second);
- $em->persist($second);
- $em->persist($first);
- In the case of bi-directional associations you have to update the fields on both sides:
- $second->setParent($first);
- /** @OneToMany(targetEntity = "Second", mappedBy = "parent" ) */
Add Comment
Please, Sign In to add comment