2013-10-10 49 views
0

CakePHP我正在使用可容忍的行爲,但我懷疑停止從中間模型的數據。CakePHP可容忍的行爲限制中級模型

假設我有這樣的結構

Song -> Tracklist -> Album 

所以,當我穿上Song ModelContainable行爲,將其與所需的字段提取出專輯數據。但在每次調用中,它也會獲取中間模型曲目列表的全部數據。

我的包含行爲是這樣的。

$contain = array('Tracklist'=>array('Album'=>array('id','name'))); 
$this-Song->find('first', array('contain'=>$contain)); 

像這樣。我的數據就像

[Tracklist] => Array 
    (
     [0] => Array 
      (
       [id] => 50 
       [album_id] => 229 
       [song_id] => 38 
       [video_link] => 
       [status] => 0 
       [featured] => 0 
       [user_id] => 
       [created] => 
       [modified_by] => 
       [modified] => 
       [Album] => Array 
        (
         [name] => Marasim 
         [slug] => marasim 
        ) 
      ) 

     [1] => Array 
      (
       [id] => 2748 
       [album_id] => 489 
       [song_id] => 38 
       [video_link] => 
       [status] => 1 
       [featured] => 0 
       [user_id] => 
       [created] => 2013-10-09 17:58:53 
       [modified_by] => 
       [modified] => 2013-10-09 17:58:53 
       [Album] => Array 
        (
         [name] => Dummy Album 
         [slug] => dummy-album 
        ) 

        ) 
      ) 
     [2] => Array 
      (
       [id] => 2749 
       [album_id] => 489 
       [song_id] => 38 
       [video_link] => 
       [status] => 1 
       [featured] => 0 
       [user_id] => 
       [created] => 2013-10-09 17:59:42 
       [modified_by] => 
       [modified] => 2013-10-09 17:59:42 
       [Album] => Array 
        (
         [name] => Dummy Album 
         [slug] => dummy-album 
        ) 
      ) 
    ) 

我只是想限制中間模型的數據。那可能嗎 ?

+1

我有同樣的問題...希望有人有魔法停止獲取中間模型。 :( –

+0

你不想檢索相冊數據,對吧? –

+0

@Moyed:我不想檢索中間模型意味着我的數據應該是'Tracklist-> 0-> Album-> AlbumData'的方式。 。我該怎麼做才能從曲目列表中提取特定的數據,或者從曲目列表中獲取特定數據(像'Tracklist-> 0('id','album_id') - > Album-> AlbumData') – Sankalp

回答

1

嘗試

$contain = array('Tracklist'=>array(
     'fields' = array('id'), 
     'Album'=>array('id','name') 
)); 
    $this-Song->find('first', array('contain'=>$contain)); 
+0

儘管我嘗試了相同的功能,如果我的關係類似於「曲目列表 - > 0->專輯 - >」,那麼它肯定會獲取像這樣的曲目 - > 0('album_id') - >相冊 - > AlbumData' – Sankalp

0
$data = $this-Song->find('first', array('contain'=>$contain)); 

// Extract the Album's of the playlist 
$data = Hash::extract($data, '{n}.Tracklist.Album'); 

// debug($data) 
[Album] => Array (
        [name] => Marasim 
        [slug] => marasim 
       ) 
... 

如果這不正是你想要的輸出,把我的你怎麼想它一個例子,我將修改我的答案。 :)