Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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
Doctrine orm DQL与Zend Framework 2/Doctrine 2的内部连接_Doctrine Orm_Zend Framework2_Dql - Fatal编程技术网

Doctrine orm DQL与Zend Framework 2/Doctrine 2的内部连接

Doctrine orm DQL与Zend Framework 2/Doctrine 2的内部连接,doctrine-orm,zend-framework2,dql,Doctrine Orm,Zend Framework2,Dql,使用此SQL语句,我可以从所有用户获取最新消息: SELECT m1.* FROM message AS m1 INNER JOIN user AS u1 ON m1.sender_id = u1.user_id INNER JOIN ( SELECT sender_id, MAX(dateSent) MaxDate FROM message WHERE receiver_id = 4 GROUP BY sender_id ) AS

使用此SQL语句,我可以从所有用户获取最新消息:

SELECT  m1.*
FROM    message AS m1
INNER JOIN user
   AS u1
   ON m1.sender_id = u1.user_id
INNER JOIN (
   SELECT   sender_id,
   MAX(dateSent) MaxDate
   FROM     message
   WHERE receiver_id = 4
   GROUP BY sender_id
) AS m2
ON m1.sender_id = m2.sender_id
AND m1.datesent = m2.MaxDate;
这些是我的Zend Framework 2应用程序中的实体:

首先,我明白了。用户可以向其他用户发送消息

/**
 * @ORM\Entity
 * @ORM\Table(name="message")
 */
class Message
{
/**
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 * @ORM\Column(type="integer")
 */
private $id;

/**
 * @ORM\ManyToOne(targetEntity="Application\Entities\User", inversedBy="messagesSent")
 * @ORM\JoinColumn(referencedColumnName="user_id")
 */
private $sender;

/**
 * @ORM\ManyToOne(targetEntity="Application\Entities\User", inversedBy="messagesReceived")
 * @ORM\JoinColumn(referencedColumnName="user_id")
 */
private $receiver;

/**
 * @ORM\Column(type="string", length=1024)
 */
private $message;
以及此处的用户实体:

/**
 * @ORM\Entity
 * @ORM\Table(name="user")
 */
class User
{
/**
 * @var int
 * @ORM\Id
 * @ORM\Column(type="integer")
 * @ORM\GeneratedValue(strategy="AUTO")
 */
protected $user_id;
尝试将SQL转换为DQL,得到以下结果:

SELECT  m1.*
FROM    Application\Entities\Message AS m1
INNER JOIN Application\Entities\User AS u1
    WITH m1.sender_id = u1.user_id
INNER JOIN (
    SELECT  sender_id,
    MAX(dateSent) MaxDate
    FROM    Application\Entities\Message
    WHERE receiver_id = 4
    GROUP BY sender_id
) AS m2
WITH m1.sender_id = m2.sender_id
AND m1.datesent = m2.MaxDate;
如果我执行它,我会从条令中得到一个错误:

[Semantical Error] line 0, col 206 near '(
      ': Error: Class '(' is not defined.

我做错了什么?

子查询在DQL的条令(据我所知)中不可用。你会写吗

public function innerJoin($join, $alias = null, $conditionType = null, $condition = null);