Discussion:
[doctrine-user] Howto eagerly fetch association with discriminator map?
Andreas Goetz
2017-10-14 14:40:18 UTC
Permalink
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
--
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.
Andreas Goetz
2017-12-25 16:39:59 UTC
Permalink
Unfortunately the problem still exists. Even updating the Aggregator
children annotation like this:

@ManyToMany(targetEntity="Entity", inversedBy="parents", fetch="EAGER")

does not lead to the children being loaded eagerly.

What am I doing wrong here?

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.
Holtkamp
2017-12-25 18:46:16 UTC
Permalink
this might be an issue/bug, when upgrading to Doctrine ORM 2.6, the
(specific) properties of an EXTRA_LAZY fetched Entity that is part of
discriminator map are not populated. In Doctrine ORM 2.5.x this worked
properly...
Post by Andreas Goetz
Unfortunately the problem still exists. Even updating the Aggregator
@ManyToMany(targetEntity="Entity", inversedBy="parents", fetch="EAGER")
does not lead to the children being loaded eagerly.
What am I doing wrong here?
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.
Andreas Goetz
2017-12-25 20:29:22 UTC
Permalink
I've had this on 2.5 already, and still on 2.6. But thank you for
confirming that this should work even with a discriminator map- I'll need
to continue investigation.

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.
Holtkamp
2017-12-25 20:37:53 UTC
Permalink
Yeah, sorry, might not be related. Reported "my" case
in https://github.com/doctrine/doctrine2/issues/6937, will investigate more
as well.
Post by Andreas Goetz
I've had this on 2.5 already, and still on 2.6. But thank you for
confirming that this should work even with a discriminator map- I'll need
to continue investigation.
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.
Loading...