教义2多级继承-如何定义联接

时间:2019-01-15 12:17:55

标签: doctrine-orm doctrine dql discriminator

我有两个表:

电子邮件:

id    message
1    This is an email message

活动:

id    related_id    related_type
66    1    email
72    1    booking
74    55    booking

在查询构建器中,如果related_type为'email',我想将Email.id加入到Activity.related_id

因此我有实体活动:

/**
 * Activity
 *
 * @ORM\Table(name="activity")
 * @ORM\Entity
 * @ORM\InheritanceType("JOINED")
 * @ORM\DiscriminatorColumn(name="related_type", type="string")
 * @ORM\DiscriminatorMap( {"email" = "Email"} )
 */
class Activity

实体电子邮件地址:

/**
 * Email
 *
 * @ORM\Table(name="email", indexes={@ORM\Index(name="contact_id_index", columns={"contact_id"})})
 * @ORM\Entity(repositoryClass="Cinolla\ApiBundle\Entity\EmailRepository")
 */
class Email extends Activity

但是,查看当前该理论正在生成的查询,它正在执行:

FROM email t0 INNER JOIN activity t1 ON t0.id = t1.id

应该这样做:

FROM email t0 INNER JOIN activity t1 ON t1.related_id = t0.id AND t1.related_type = 'email'

  • 我在哪里定义应在related_id上加入电子邮件?
  • 为什么它不包含AND t1.related_type = 'email'

0 个答案:

没有答案