我对 Kohana ORM 中的关系有疑问。我有三个模型:用户、歌曲和标签。
User {
has many Songs;
has many Tags; (followed tags)
}
Song {
belongs to User;
has many Tags;
}
Tag {
has many Users;
has many Songs;
}
例子:
- 用户 'Naimad' 使用以下标签:Deadmau5 和 Inpetto。
- 每个标签有两首歌:
- Deadmau5 标签有:Veldt 和 Strobe,
- Inpetto 标签有:托卡的奇迹和风暴。
我想从用户后面的标签中获取这些歌曲,我不知道该怎么做。我知道这是愚蠢的例子,但我在发布这个问题之前尝试过:
$songs = ORM::factory('user', array('name' => 'Naimad'))
->tags
->songs
->find_all();