I get unnecessary queries then entity has ManyToOne relationship with 
abstract class. My classes structure:

/**
 * @ORM\Entity
 * @ORM\Table(name="tb_payment_info")
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="type", type="integer")
 * @ORM\DiscriminatorMap({
 *          "0" = "PaymentInfoPaypal",
 *          "1" = "PaymentInfoSkrill",
 * })
 */
abstract class AbstractPaymentInfo
{
    /**
     * @ORM\Column(name="payment_info_id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;
}

/**
 * @ORM\Entity
 * @ORM\Table(name="tb_payment_info_paypal")
 */
class PaymentInfoPaypal extends AbstractPaymentInfo
{
}

/**
 * @ORM\Entity
 * @ORM\Table(name="tb_payment_info_skrill")
 */
class PaymentInfoSkrill extends AbstractPaymentInfo
{
}

My Payout class contains payment_info_id column from tb_payment_info table.

/**
 * @ORM\Entity
 * @ORM\Table(name="tb_payout")
 */
class Payout
{
    /**
     * @var AbstractPaymentInfo
     *
     * @ORM\ManyToOne(targetEntity="AbstractPaymentInfo")
     * @ORM\JoinColumn(name="payment_info_id", 
referencedColumnName="payment_info_id")
     */
    private $paymentInfo;
}

When I try to get any Payout entity, its paymentInfo initialize 
automatically. So:

$this->getEntityManager()->getRepository('TuoPayBundle:Payout')->find(255);

got 2 queries: first for Payout and second for its paymentInfo

$this->getEntityManager()->getRepository('TuoPayBundle:Payout')->findBy(['id'=>[255,256]]);

got 3 queries: first for Payout and second, third separate queries to init 
paymentInfo

How to achieve lazy load?

-- 
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 https://groups.google.com/group/doctrine-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to