Ok this is what I have set up:
Artist -> hasMany Album
Album -> belongsTo Artist
Album -> belongsTo Label
Album-> hasMany Track
Label-> hasMany Album
Track-> belongsTo Album
so fa so good....
I provide the name of the Artist and the name of the Album and want to
get results from each table:
$this->Album->find('all', array('conditions' => array('Album.slug'=>
$thisAlbum, 'Artist.slug'=>$thisArtist), 'fields'=>array('Album.name',
'Artist.name', 'Label.name'), 'recursive'=>1));
This the array I get:
Array
(
[0] => Array
(
[Album] => Array
(
[name] => The Art Of Breaking
[id] => 1
)
[Artist] => Array
(
[name] => Thousand Foot Krutch
)
[Label] => Array
(
[name] => Tooth & Nail
)
[Track] => Array
(
[0] => Array
(
[id] => 1
[album_id] => 1
[name] => Hand Granade
[lyrics] =>
[slug] => handgranade
[created] => 2009-10-16 22:09:19
[modified] => 0000-00-00 00:00:00
)
[1] => Array
(
[id] => 2
[album_id] => 1
[name] => Breathe
[lyrics] =>
[slug] => breathe
[created] => 2009-10-16 22:55:16
[modified] => 0000-00-00 00:00:00
)
)
)
)
Which is what I want.. except that I cannot specify what fields I want
to select in the table Tracks, because it's a separate query.
Look at the queries:
First:
SELECT `Album`.`name`, `Artist`.`name`, `Label`.`name`, `Album`.`id`
FROM `albums` AS `Album` LEFT JOIN `artists` AS `Artist` ON
(`Album`.`artist_id` = `Artist`.`id`) LEFT JOIN `labels` AS `Label` ON
(`Album`.`label_id` = `Label`.`id`) WHERE `Album`.`slug` =
'theartofbreaking' AND `Artist`.`slug` = 'thousandfootkrutch'
Second:
SELECT `Track`.`id`, `Track`.`album_id`, `Track`.`name`,
`Track`.`lyrics`, `Track`.`slug`, `Track`.`created`,
`Track`.`modified` FROM `tracks` AS `Track` WHERE `Track`.`album_id` =
(1)
Is there a way to tell find() what fields in Track to select? Do I
have to do another find()?
The only thing I can think of is to do recursive = 0 and run another
find() for Track.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---