> Video hasMany AlbumVideo; AlbumVideo hasMany Albums.
This implies that Album belongsTo AlbumVideo and AlbumVideo belongsTo
Video; i.e:
Video : [id, ...]
AlbumVideo: [id, video_id, ...]
Album: [id, album_video_id, ...]
> Now I would like to search in Album and song title.
You're not being clear on exactly what you want to search for. You're
calling the result '$Videos' but you're actually searching on Album.
I'm assuming you're searching for "all Albums entitled 'CANTINA' which
belong to a Video with the track title 'PATO'". [1]
This is not the same, for example, as "all Videos with a track title
'PATO' and belonging to an album with title 'CANTINA'" [2]. (Although
the same data will be present in the returned array, the data will be
duplicated in different ways).
So, assuming [1], the problem is that CakePHP does not perform a left
join on recursive belongsTo relationships. This is relatively easy and
painless to fix:
// (Note the aliasing of `Video` to `ParentVideo` to avoid
collisions.)
$this->Video->Album->bindModel(array(
'belongsTo' => array(
'ParentVideo' => array(
'className' => 'Video',
'foreignKey' => false,
'conditions' => 'AlbumVideo.video_id=Video.id'
)
)
));
// This will work with $recursive >= 0
$albums = $this->Video->Album-
>findAll(array("ParentVideo.track_title='PATO'",
"Album.title='CANTINA'"));
/* Result:
array(
[0] => array(
'Album' => array('id' => ..., 'title' => 'CANTINA'),
'AlbumVideo' => array(...),
'ParentVideo' => array('id' => ..., 'track_title' => 'PATO')
),
[2] => ...
);
*/
If you're looking for [2] it's a little more complicated : you need
unique rows, grouping, and lots more dynamic bindings. If this is
going to be a regularly-called function in your application, perhaps a
rethink of the database structure is needed? [not a criticism, just a
suggestion]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---