Kohana ORM 在多对多关系中获得一项记录
我有两个表(项目/标签)。项目具有并属于许多标签 - 标签具有并属于许多项目。
对我来说,获取所有相关标签没有问题,例如:
$item = ORM::factory('item', 4);
foreach($item->tags as $tag){....}
但是我如何才能只获取一个......也许是一个特定的标签?
提前致谢!
I've got two tables (items / tags). Item has and belongs to many tags - tag has and belongs to many items.
It's no problem for me to fetch all related tags like:
$item = ORM::factory('item', 4);
foreach($item->tags as $tag){....}
But how can i fetch only one... and maybe a specific one?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Kohana 3 中,您可以这样做:
在
where()
中输入您想要的条件。编辑:
我做了一些研究,在 Kohana 2.3.x 中
where
语法是不同的,而不是where('somevalue', '=', $value )
你应该写where('somevalue', $value)
。或者where('somevalue >', $value)
、where('somevalue !=', $value)
等。In Kohana 3 you can do this:
Inside
where()
you put the condition you want.Edit:
I did a little research and in Kohana 2.3.x the
where
syntax is different, instead ofwhere('somevalue', '=', $value)
you should writewhere('somevalue', $value)
. Orwhere('somevalue >', $value)
,where('somevalue !=', $value)
, etc.