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 passtag.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.
精彩评论