php - Symfony2 mapping works for one entity but not the other -
i have 2 entitites mapped together.
skin.php :
/** * @var cmselement * * @orm\manytoone(targetentity="cmselement") * @orm\joincolumns({ * @orm\joincolumn(name="homepage_id", referencedcolumnname="id") * }) */ private $homepage;
cmselement.php :
/** * @var skin * * @orm\manytoone(targetentity="skin") * @orm\joincolumns({ * @orm\joincolumn(name="skin_id", referencedcolumnname="id") * }) */ private $skinid;
and thats it. skin table mapped correctly, id of cmselement. in cmselement dont needed skinid... stays null. codes identical, why doesnt work?
an example better understanding:
skin:
id: 1 homepage_id: 2
cmselement:
id: 2 skin_id: null
in order set manytoone relation, have specify in both ways this:
// skin.php /** * @var cmselement * * @orm\onetomany(targetentity="cmselement", mappedby="skinid") * @orm\joincolumns({ * @orm\joincolumn(name="homepage_id", referencedcolumnname="id") * }) */ private $homepage; // cmselement.php : /** * @var skin * * @orm\manytoone(targetentity="skin", inversedby="homepage") * @orm\joincolumns({ * @orm\joincolumn(name="skin_id", referencedcolumnname="id") * }) */ private $skinid;
but, please take care of points:
- use $skin instead of $skinid because referencing entity, not id property
- the relation manytoone refer side multiple entity linked side 1 entity, please define wich multiple side , single one. assumed cmselement multiple side used manytoone on cmselement , onetomany other. if wrong, please invert this.
- use plurial name attribute @ multiple side. instance if set 1 $skin many $homepages, sure tu use final "s", it's easier understand.
here can find informations in order relation in right way: sf2 doc
Comments
Post a Comment