Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Symfony2和条令:如何按依赖实体字段对实体集合排序_Php_Symfony_Doctrine Orm_Doctrine - Fatal编程技术网

Php Symfony2和条令:如何按依赖实体字段对实体集合排序

Php Symfony2和条令:如何按依赖实体字段对实体集合排序,php,symfony,doctrine-orm,doctrine,Php,Symfony,Doctrine Orm,Doctrine,在我的sf2项目中,我通过调用来访问实体集合: $user_payment_info_datas = $user->getUserPaymentInfoDatas(); 在用户实体中有: /** * @ORM\OneToMany(targetEntity="UserPaymentInfoData", mappedBy="user") * @ORM\OrderBy({"payment_info" = "ASC", "payment_info_data" = "ASC"}) */ pr

在我的sf2项目中,我通过调用来访问实体集合:

$user_payment_info_datas = $user->getUserPaymentInfoDatas();
在用户实体中有:

/**
 * @ORM\OneToMany(targetEntity="UserPaymentInfoData", mappedBy="user")
 * @ORM\OrderBy({"payment_info" = "ASC", "payment_info_data" = "ASC"})
 */
private $user_payment_info_datas;
所以这是1:n关系,用户有许多UserPaymentInfoData。但是,还有另一个名为PaymentInfoData的实体,它包含UserPaymentInfoData的实际值。所以关系是

User -> UserPaymentInfoData -> PaymentInfoData.
因此,就UserPaymentInfoData中的注释而言:

/**
 * @ORM\ManyToOne(targetEntity="PaymentInfoData", inversedBy="user_payment_info_datas")
 * @ORM\JoinColumn(name="payment_info_id", referencedColumnName="id")
 * @ORM\OrderBy({"title"="ASC"})
 */
private $payment_info_data;
我需要整理你寄回来的收藏品

$user_payment_info_datas = $user->getUserPaymentInfoDatas();
从PaymentInfoData按字段升序,我们将其称为“title”,而不是UserPaymentInfoData

我可以用条令注释来做这件事吗?还是不写DQL

我知道我可以用:

    $user_payment_info_datas = $em->getRepository('STMainBundle:UserPaymentInfoData')
        ->createQueryBuilder('upid')
        ->innerJoin ('upid.payment_info_data', 'pid')
        ->where('upid.user = :user')
        ->addOrderBy('upid.payment_info', 'ASC')
        ->addOrderBy('pid.title', 'ASC')
        ->setParameter('user', $user)
        ->getQuery()
        ->getResult();

但问题是,是否可以只保留注释,因为我需要在几个地方修复它,并且只更改注释而不在两个地方创建查询生成器会很方便

注释不会为您提供那种级别的控制。让自己成为一个UserPaymentInfoDataRepository,并在那里添加排序查询。也可以直接在User::getSortedUserPaymentInfoDatas中使用usort并在本地进行排序。但是存储库方法可能是你最好的选择。好的,明白了。谢谢你的回答!