[英]How to implement Multi relationship ORM in Kohana?
I have problem with relationships in Kohana ORM. 我在Kohana ORM中的关系存在问题。 I have three models: User, Song and Tag.
我有三个模型:用户,歌曲和标签。
User {
has many Songs;
has many Tags; (followed tags)
}
Song {
belongs to User;
has many Tags;
}
Tag {
has many Users;
has many Songs;
}
Example: 例:
I want to get these songs from tags followed by user, I don't know how to do this. 我想从用户后面的标签中获取这些歌曲,但我不知道该怎么做。 I know that is stupid example, but I tried before I posted this question:
我知道这是愚蠢的示例,但是我在发布此问题之前尝试过:
$songs = ORM::factory('user', array('name' => 'Naimad'))
->tags
->songs
->find_all();
I think you need to use the ->with('tag')->with('song') 我认为您需要使用-> with('tag')-> with('song')
$songs = ORM::factory('user', array('name' => 'Naimad'))
->with('tags')
->with('songs')
->find_all();
then to access the value do a loop on the objects $s->tags->field_name ... etc 然后访问值在对象$ s-> tags-> field_name ...等上循环
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.