开发者

Kohana3 ORM Relationship Clarification needed

Have another problem with ORM.

I have three models: user.php, tag.php and /user/tag.php.

user.php

name

pass

tag.php

name

slug

/user/tag.php

id

tag_id

user_id

I created has many relation between user and user_tag model. So I'm getting users tags using following code:

$user = ORM::factory('user', $user_id);
$tags = $user->tags->find_all();

And here's my question, is it possible to build relation that will be automatically query for 开发者_开发百科tags names too (or should I use join() or leave ORM and take query builder for this)?


All you need is a has_many through relationship:

$protected $_has_many = array(
   'tags' => array(
      'model'   => 'tag',
      'through' => 'user_tag',
   ),
);

So, $user->tags->find_all() will return an array of Model_Tag objects.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜