我应该如何在学说存储库查询中按鉴别器列进行排序?
我有一个非常简单的设置,我有不同类型的付款详细信息,可以是信用卡 (CC) 或借记单 (DO)。
所以我实现了一个单表继承映射策略来实现这一点,但是当我尝试按鉴别器列排序时,问题就出现了,因为基类中不存在鉴别器列。
存储库功能:
public function getPaymentDetails (ClientContactInterface $clientContact)
{
$dql = 'SELECT pd
from
AccountingBundle:PaymentDetail pd
JOIN ClientProductBundle:ClientProduct cp
WITH cp.payment_detail_id = pd.id
WHERE
cp.payment_detail_id = pd.id
and cp.client_contact_id = :client_contact_id
GROUP BY pd.id
ORDER BY pd.method_type'; // Since pd.method_type is the discriminator column, I cannot order by it. And I need to be able to.
$em = $this->getEntityManager();
$query = $em->createQuery($dql)->setParameter('client_contact_id', $clientContact->getId());
return $query->getResult();
}
Base PaymentDetail 实体:
/**
* @ORM\Entity(repositoryClass="AccountingBundle\Repository\PaymentDetailRepository")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\Table(name="PaymentDetails")
* @ORM\DiscriminatorColumn(name="PaymentMethodType", type="string")
* @ORM\DiscriminatorMap({ "DO" = "DOPaymentDetail", "CC" = "CCPaymentDetail"})
*/
class PaymentDetail implements PaymentDetailInterface
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/* etc... */
}
借记单 PaymentDetail 实体:
/**
* AccountingBundle\Entity\DOPaymentDetail
*
* @ORM\Table(name="PaymentDetails")
* @ORM\Entity
*/
class DOPaymentDetail extends PaymentDetail implements DOPaymentDetailInterface
{
/**
* @var string $account_holder
*
* @ORM\Column(name="DOAccountHolder", type="string", length=255)
*/
protected $account_holder;
/* etc... */
}
信用卡 PaymentDetail 实体:
/**
* AccountingBundle\Entity\CCPaymentDetail
*
* @ORM\Table(name="PaymentDetails")
* @ORM\Entity
*/
class CCPaymentDetail extends PaymentDetail implements CCPaymentDetailInterface
{
/**
*
* @var string $card_holder
*
* @ORM\Column(name="CCCardHolder", type="string", length=255)
*/
protected $card_holder;
/* etc... */
}
当我尝试这样做时,我得到了这个错误,
Error: Class AccountingBundle\Entity\PaymentDetail has no field or association named method_type")