0

I want to do one query, and I thought I could write it in the following two ways:

SELECT c, p
FROM MyBundle:Car c
    JOIN c.person p
WHERE
    p.name =  :name

and

SELECT c, p
FROM MyBundle:Person p
    JOIN p.car c
WHERE
    p.name =  :name

Since in both cases I was asking for "c, p" in that particular order, I was expecting the query to return the same thing, however, in the first case the object I get is of the type Car and on the second case is of type Person.

I don't understand why this happens, any light would be appreciated.

4

1 回答 1

0

第一个说:给我每辆车都附在一个人身上,其中人的名字是 :name。当然,这是一个汽车清单。

第二个说给我每个连接到汽车的人,其中人的名字是:name。当然,这是一份人员名单。

由于它们是连接的,因此学说热切将相关实体加载为主要选择的字段,这由 from 子句指示。

基本上,这是面向对象的视图,这就是 dql 的工作方式。您认为它们应该相同的论点是面向元组的视图,这就是 sql 的工作方式。掌握这一概念对于有效使用学说至关重要。

于 2013-04-16T19:49:37.197 回答