0
votes

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)?

1

1 Answers

0
votes

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.