教义加入无关系 [英] doctrine join without relation

查看:112
本文介绍了教义加入无关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

这是否可以在不使用关系的情况下连接在doctrine ORM中的表?

我有2个课月和蔬菜。他们在一起没有任何关系。

I have 2 classes Month and Vegetable. They don't have any relation together.

我想玩SQL:
SELECT * FROM month,vegetable

I would like to play the SQL : SELECT * FROM month, vegetable

在MySQL中,它工作得很好。我在Doctrine中尝试:

In MySQL it works perfectly. I try it like that in Doctrine:

    $months = Doctrine_Query::create()
      ->select('m.*, v.*')
      ->from('month m, vegetable v')
      ->execute();

当我尝试,我得到:

"vegetable" with an alias of "v" in your query does not reference the parent component it is related to.

有谁知道为什么?

推荐答案

第一个原则是使用DQl而不是SQL。

First Doctrine is using DQl and not SQL.

DQL正在使用对象,所以Doctrine尝试从一个月到一个菜单获得关系,但没有任何关系。

DQL is using Objects, so Doctrine try to get a Relation from month to vegetable, but there isn't any relation.

当您希望这与Doctrine有关时,您必须执行两个查询并将其作为Array并将其加入。

When you want this to do with Doctrine, you must do two Queries and fetch them as Array and join them.

这篇关于教义加入无关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆