Andreas Goetz
2017-10-14 14:40:18 UTC
I have Entites and Aggregators which are entities with children. When
retrieving entities I'd like to eagerly fetch children for entities of type
aggregator:
$dql = 'SELECT e, p
FROM Volkszaehler\Model\Entity e
LEFT JOIN e.properties p
WHERE e.uuid = :uuid';
$q = $this->em->createQuery($dql)->setParameter('uuid', $uuid);
$q->setFetchMode("Volkszaehler\Model\Aggregator", "children",
ClassMetadata::FETCH_EAGER);
Unfortunately this doesn't work- children will initially not be populated.
This is the entity:
/**
* @Entity
* @Table(name="entities")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="class", type="string")
* @DiscriminatorMap({
* "channel" = "Channel",
* "aggregator" = "Aggregator"
* })
* @HasLifecycleCallbacks
*/
abstract class Entity {
and this the aggregator:
/**
* @Entity
*/
class Aggregator extends Entity {
/**
* @ManyToMany(targetEntity="Entity", inversedBy="parents")
* @JoinTable(name="entities_in_aggregator",
* joinColumns={@JoinColumn(name="parent_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="child_id",
referencedColumnName="id")}
* )
*/
protected $children = NULL;
Is it possible to use eager fetching with disciminated entity types?
Thanks,
Andreas
retrieving entities I'd like to eagerly fetch children for entities of type
aggregator:
$dql = 'SELECT e, p
FROM Volkszaehler\Model\Entity e
LEFT JOIN e.properties p
WHERE e.uuid = :uuid';
$q = $this->em->createQuery($dql)->setParameter('uuid', $uuid);
$q->setFetchMode("Volkszaehler\Model\Aggregator", "children",
ClassMetadata::FETCH_EAGER);
Unfortunately this doesn't work- children will initially not be populated.
This is the entity:
/**
* @Entity
* @Table(name="entities")
* @InheritanceType("SINGLE_TABLE")
* @DiscriminatorColumn(name="class", type="string")
* @DiscriminatorMap({
* "channel" = "Channel",
* "aggregator" = "Aggregator"
* })
* @HasLifecycleCallbacks
*/
abstract class Entity {
and this the aggregator:
/**
* @Entity
*/
class Aggregator extends Entity {
/**
* @ManyToMany(targetEntity="Entity", inversedBy="parents")
* @JoinTable(name="entities_in_aggregator",
* joinColumns={@JoinColumn(name="parent_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="child_id",
referencedColumnName="id")}
* )
*/
protected $children = NULL;
Is it possible to use eager fetching with disciminated entity types?
Thanks,
Andreas
--
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 doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.
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 doctrine-user+***@googlegroups.com.
To post to this group, send email to doctrine-***@googlegroups.com.
Visit this group at https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.