Pergunta

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!

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top