0

I have a problem in my DQL query. I have a table which has 3 foreign keys userId, userRId and userAId. Two of those foreign keys may be NULL.

I want to join all the foreign keys in the query but i don't know how to join two or three foreign keys between the same tables. (see query ) Could somebody give me some ideas??

   **TABLE A**
   id    userId   userRId   userAId
   1     2        NULL      NULL
   1     2         1        NULL
   1     2        NULL         1

**TABLE USER**
userId  name
  2     xxxx
  1     xxxx

The DQL query:

"SELECT FROM nasyBundle:A a JOIN a.userId u , a JOIN userRId , a JOIN userAid
         WHERE ...
4

1 回答 1

3

在 DQL 中,您对对象(实体)而不是表(基于映射)进行操作。所以当你有这样的实体时:

class User
{
    private $id;
    private $name;
}

class TableA
{
    private $id;
    private $user;
    private $userR;
    private $userA;
}

您可以像这样创建查询(当您有有效的映射时)

SELECT a
FROM nastyBundle:TableA a
INNER JOIN a.user u
LEFT JOIN a.userR ur
LEFT JOIN a.userA ua

但是,是的,要使用它,您需要映射信息。如果您没有映射,您可以使用学说生成它:映射:导入只需输入您的 symfony 项目以阅读更多信息php app/console help doctrine:mapping:import

于 2012-07-15T07:26:07.077 回答