0
votes

CakePHP I am using containable behaviour but I have doubt to stop the data from the intermediate model.

SUppose I have this structure

Song -> Tracklist -> Album

So when I put Containable behavior on Song Model it fetch out Album data with desired field. But in every call it also fetch whole data of intermediate model Tracklist.

My containable behaviour is like this.

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

Like this. My data is like

 [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
                    )
            )
     )

I just want to limit data from intermediate Model. Is that possible ?

2
I have the same problem... Hope someone has the magic to stop the intermediate model from being fetch. :( - Domingo C.
You dont want to retrieve Album data, right ? - Moyed Ansari
@Moyed: I don't want to retrieve intermediate model means My data should be in the way Tracklist->0->Album->AlbumData. Like this.. What shall I do to fetch specific data from Tracklist or none from Tracklist Like this way (Tracklist->0('id', 'album_id')->Album->AlbumData). - Sankalp

2 Answers

1
votes

Try

  $contain =  array('Tracklist'=>array(
        'fields' = array('id'),
        'Album'=>array('id','name')
  ));
  $this-Song->find('first', array('contain'=>$contain));
0
votes
$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
                 )
...

If this is not exactly the output you want, put me a example of how do you want it, i will edit my answer. :)