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 children

in 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

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -