I've come up against this problem pretty early on in 2 projects I am
trying to write with CakePHP. It seems a pretty common type of query,
so hopefully I am just looking in the wrong area for an answer or
misunderstanding relationships rather than having to write manual
queries in my models.
Below is an example using artists, albums and tracks.
=========
artists
id
name
---
artists hasMany (album,track)
=========
albums
id
artist_id
name
---
albums hasMany (tracks,album)
albums belongsTo (artist)
=========
tracks
id
album_id
name
---
tracks belongsTo (album)
=========
If I display a list of tracks, I would also like to have the album and
artist names displayed. All goes well getting the album name, and even
the artist id, but I can't work out how to have the artist name
returned in the query.
The query that cakePHP runs for tracks is;
select tracks.id, tracks.name, albums.id, albums.name, album.artist_id
FROM tracks INNER JOIN albums ON tracks.album_id = albums.id
The query that I want run is;
select tracks.id, tracks.name, albums.id, albums.name, artists.id,
artists.name FROM tracks INNER JOIN albums ON tracks.album_id =
albums.id INNER JOIN artists ON albums.artist_id = artists.id
I know I could adjust the recursive level, but then that just does
another n queries for each record. Is there a way in relationships I
could adjust things so that a query equivalent to that above is
returned?
Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---