Kohana ORM get one record in many-to-many relationship
-
02-10-2019 - |
문제
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!
해결책
In Kohana 3 you can do this:
$item = ORM::factory('item', 4);
$tag = $item->tags->where('somevalue','=',$value)->find();
if($tag->loaded()) {...}
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 of where('somevalue', '=', $value)
you should write where('somevalue', $value)
. Or where('somevalue >', $value)
, where('somevalue !=', $value)
, etc.
제휴하지 않습니다 StackOverflow