2012-06-17 31 views
0

我有在Kohana的ORM的關係問題。我有三種模式:用戶,歌曲和標籤。如何實現多關係ORM在Kohana的?

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。
  • 每個標籤有兩首歌曲:
    1. Deadmau5標籤有:大草原和頻閃燈,
    2. Inpetto標籤有:託卡的奇蹟和風暴。

我想從標籤,然後用戶獲得這些歌曲,我不知道如何做到這一點。我知道這是愚蠢的例子,但我想之前我張貼了這個問題:

$songs = ORM::factory('user', array('name' => 'Naimad')) 
    ->tags 
    ->songs 
    ->find_all(); 

回答

0

我認爲你需要使用- >使用(「歌」)

- 與(「標籤」)>
$songs = ORM::factory('user', array('name' => 'Naimad')) 
    ->with('tags') 
    ->with('songs') 
    ->find_all(); 

然後訪問值做一個循環上的對象$ S-> tags-> FIELD_NAME ...等