[英]Doctrine Join DQL
I's like to do a join between 2 tables on a specific ID. 我想在特定ID的2个表之间进行联接。 At the moment, I have this DQL: 目前,我有这个DQL:
$q = Doctrine_Query::create()
->select('e.*, i.itemName, i.itemtypeId')
->from('Model_EventItem e')
->leftJoin('Model_Item i ON e.itemId = i.itemId')
->where('e.eventitemId = ?', $event->eventId)
->orderBy('i.itemName ASC');
The result is empty, although my eventId has a value ... Can you help me please? 结果是空的,尽管我的eventId有一个值...您能帮我吗? I there somewhere a tutorial on DQL-joins? 我在某处有关于DQL-join的教程吗? I don't get it right with the help of the Doctrine documentation. 我在教义文档的帮助下做得不好。
Thanks! 谢谢!
PS I have doctrine working in combination with Zend Framework. 附言:我的理论与Zend Framework结合使用。
you need add a relation to the model and join the tables using the relation 您需要向模型添加一个关系并使用该关系连接表
$q = Doctrine_Query::create()
->select('e.*, i.itemName, i.itemtypeId')
->from('Model_EventItem e')
->leftJoin('Model_EventItem.Model_Item i')
->where('e.eventitemId = ?', $event->eventId)
->orderBy('i.itemName ASC');
you should change the name in the left join from Model_EventItem
to e
您应该将左连接中的名称从Model_EventItem
为e
$q = Doctrine_Query::create()
->select('e.*, i.itemName, i.itemtypeId')
->from('Model_EventItem e')
->leftJoin('Model_EventItem.Model_Item i')
->where('e.eventitemId = ?', $event->eventId)
->orderBy('i.itemName ASC');
$q = Doctrine_Query::create()
->select('e.*, i.itemName, i.itemtypeId')
->from('Model_EventItem e, e.Model_Item i')
->where('e.eventitemId = ?', $event->eventId)
->orderBy('i.itemName ASC');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.