通过一个查询请求多个类似模型

时间:2018-03-29 10:35:30

标签: symfony orm doctrine

Symfony如何实现响应多个模型的查询?

想象一下,我们有3个模型:AdvAdvT1 extends AdvAdvT2 extends Adv

因此,目标是从查询结果中检索所有模型AdvT1和AdvT2,其中在表adv的列中设置了相应的模型类型。

SELECT * FROM ONLY adv NATURAL FULL JOIN adv_t1 NATURAL FULL JOIN adv_t2 order by id;

表架构是:

CREATE TABLE public.adv (
    id integer NOT NULL,
    title text,
    price integer
);

CREATE TABLE public.adv_t1 (
    size integer
) INHERITS (public.adv);

CREATE TABLE public.adv_t2 (
    color integer
) INHERITS (public.adv);

以下是对左边连接与自然连接进行比较的查询说明的分析。

"SELECT * FROM ONLY adv NATURAL FULL JOIN adv_t1 NATURAL FULL JOIN adv_t2 order by id"; 

费用 - 245.87;持续时间 - 0.132

"SELECT * FROM adv LEFT JOIN adv_t1 ON adv_t1.id = adv.id LEFT JOIN adv_t2 ON adv_t2.id = adv.id order by adv.id"; 

费用 - 1538.94;持续时间 - 0.059

0 个答案:

没有答案