Kohana 3 ORM:如何执行具有2个多对多关系的查询
我有一个定义了 2 个多对多关系的产品模型。
protected $_has_many = array
(
'foodcats' => array('model' => 'foodcat', 'through' => 'products_foodcats'),
'foodgroups' => array('model' => 'foodgroup', 'through' => 'products_foodgroups')
)
我需要一个查询,在其中查找具有给定 foodcat id 和给定食品组名称的产品。 我知道我可以执行以下操作来获取具有给定 foodcat id 的所有产品
$foodcat = ORM::factory('foodcat',$foodCatId);
$products = $foodcat->products->find_all();
,但是如何查询该 foodcat 中同时位于食品组“Entrees”中的产品?
谢谢!
I have a products model with 2 many to many relationships defined.
protected $_has_many = array
(
'foodcats' => array('model' => 'foodcat', 'through' => 'products_foodcats'),
'foodgroups' => array('model' => 'foodgroup', 'through' => 'products_foodgroups')
)
I need a query where I find products with a given foodcat id and a given foodgroup name.
I know I can do the following to get all products with a given foodcat id
$foodcat = ORM::factory('foodcat',$foodCatId);
$products = $foodcat->products->find_all();
But how do I query for products in that foodcat that also are in the foodgroup 'Entrees'?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简单地;你不知道。你需要的是 INNER JOIN,比如;
Simply; you don't. What you need is INNER JOIN, like;
在 Kohana 3.1 中,如果不使用
DB::expr
,将会给出未知列错误。in Kohana 3.1 without using
DB::expr
, will give unknown column error.