Hi there.
I'm thinking about the Doctrine Inheritance and his eager loading
limitation when the classes at the upper levels of the inheritance are
target with “targetEntity” in a 1_parent->n_children relation.
It is totally comprehensible architecturally-wise, but because I *really*
need this type of mapping in the association I've ended up with a
workaround for prevent the eager loading: disabling the relation mapping
and injecting a static repository inside the entity with a raw emulation of
the apis:
static $nodeRepoository;
protected $parent;
protected $children;
/*
* @ORM\Column(type="integer", name="parent_id")
*/
protected $parentId;
public function getParent()
{
if(!$this->parent)
{
$this->parent = ($this->parentId)
? self::$nodeRepoository->find($this->parentId)
: null;
}
return $this->parent;
}
public function getChildren()
{
if(!$this->children)
{
$this->children = new
ArrayCollection(self::$nodeRepoository->findBy([
'parentId' => $this->id
]
));
}
return $this->children;
}
public function setParent(AbstractNode $parent)
{
$this->parent = $parent;
$this->parentId = $parent->getId();
return $this;
}
So, except that inject the repository inside the entity is really BAD (I
agree) plus the problem with the fake mapping (SchemaTool incongruences, no
real ArrayCollection persist, manually set the foreign constaint etc...),
this workaround works fine.
Might it not be possible to implement something like that natively into
the core? Maybe with a special check for Inheritance mapping or a new fetch
type like "fetch=QUERY" into relation that simple triggers a new query
before hydratation? Any discussion about the topic?
--
You received this message because you are subscribed to the Google Groups
"doctrine-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.