How to chain several ORM relationships in Kohana 3?
fairly simple question I think that I couldn't find the answer to in the docs (http://kohanaframework.org/guide/orm开发者_开发百科/relationships)
I have the need to define relationships with several Models (in bold) (each has a corresponding table) at once, if that makes sense.
I have several models that have slightly intertwined relationships.
the connection model $_belongs_to
the user. This code works fine, great. But the connection also needs to $_has_one
song (i can haz cheezeburger??), and to $has_one
keyword, if that makes sense.
This is because I want to access the song name and keyword name through the connection, for instance using $connection->song->name
, and then $connection->keyword->name
...
SO, the problem is I can't seem to chain the relationships detailed above, as I can only declare one relationship per model.... so how do I do this? Or maybe there's another much easier way of doing it that I'm unaware of...
I presume I'm being a n00b and would love some help on this. Cheers.
You can collect relationships in arrays:
class Model_Connection extends ORM {
protected $_belongs_to = array(
'user' => array(),
);
protected $_has_one = array(
'song' => array(),
'keyword' => array(),
);
}
PS. But it seems like both song
and keyword
must be in a $_belongs_to
property (one song
has many connections
, one connection
belongs to song
).
精彩评论