且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取主义DQL结果是SQL方式

更新时间:2023-11-19 15:46:34

不幸的是,目前没有实现这一点的简单方式。

Unfortunately, there's no current easy way of achieve this. However, there's a way that you could get that result.

创建一个名为UserTransactionDTO的类,并接受2个构造函数参数:用户和事务。

Create a class named UserTransactionDTO and accept 2 constructor arguments: User and Transaction.

现在重写您的DQL查询,如下所示:

Now rewrite your DQL query like this:

SELECT NEW UserTransactionDTO(user, transaction)
  FROM Model\User u
  JOIN Model\Transaction t WITH t.user = u

这应该给你一个匹配你想要的行为(UserTransactionDTO对象的列表)的结果,允许你访问一个记录上的用户和事务。

This should give you a result that matches your desired behavior (a list of UserTransactionDTO objects), allowing you to access both User and Transaction on a single record.