jointable - Access join table fields in Doctrine2 -
jointable - Access join table fields in Doctrine2 -
here (simplified) category entity:
/** * @orm\entity */ class category { /** * @orm\id * @orm\column(type="integer") * @orm\generatedvalue(strategy="auto") */ protected $id = null; /** * @orm\manytoone(targetentity="category", inversedby="children", fetch="eager") */ protected $parent = null; /** * @orm\onetomany(targetentity="category", mappedby="parent", fetch="lazy") * @orm\jointable(name="category_tree", * joincolumns={@orm\joincolumn(name="parent_id", referencedcolumnname="id")}, * inversejoincolumns={@orm\joincolumn(name="child_id", referencedcolumnname="id")} * ) */ protected $children; }
can write dql query give me result with, each category:
its id an array ids of childrenin sql it's pretty simple of course, bring together tables seem transparent in doctrine.
if need references, there's handy getreference() method, utilize this:
$item = $this->em->getreference('entity\item', $id);
alternatively, set associated entities extra_lazy. depends on need, 2 approaches cut down overhead.
doctrine2 jointable
Comments
Post a Comment