/** @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;
}
Here is the problem with taking into ArrayCollection $secondList elements from Second class. Second ManyToOne relation is working properly. Perhaps I did something wrong in initializing a persistance (because First_Id in SQL base is null always).
$first = new Second();
$second = new First();
$first->getSecond()->add($second);
$em->persist($second);
$em->persist($first);
Any suggestions?
Doctrine2 docs say this:
This means that you’ll have to do something like:
As
$secondtable has the foreign key.Or you could add a
cascade={"persist"}option to the$first->secondListproperty.