Sorry, I meant Genre HasMany Song, not Song HasMany Genre.

On Nov 16, 12:09 pm, emptywalls <[email protected]> wrote:
> I'm new to CakePHP and I'm trying to use the Containable behavior. My
> model is pretty complex, with a HasAndBelongsToMany and some other
> joins.
>
> I've got my Artist Model, which HasAndBelongsToMany Song (join table
> artists_songs).
> Song HasAndBelongsToMany Artist, and HasMany Genre.
>
> With an Artist, I'd like to list the artist name, and the genre of
> songs they have:
> Artist: Beatles
> Genres: Pop, Rock.
>
> I've gotten to the point where I can list the artist name and the
> genres, but genre is coming up for however many songs the artist has.
> If the artist has 5 songs, I'm ending up with this:
> Artist: Beatles
> Genres: Pop, Pop, Pop, Rock, Rock
>
> I figured I'd use the Containable behavior and request DISTINCT
> genre_id from Song. When I do this, I'm seeing the SQL query do this:
> DISTINCT Song.genre_id, Song.genre_id
>
> I figured this was because Containable is automatically grabbing the
> foreign keys it needs to make this association, which is usually
> awesome.
>
> At the bottom of the documentation for 
> Containable:http://book.cakephp.org/view/474/Containable
> There is mention of options to turn autoFields off, if you're having
> problems with aggregating fields. This sounds like what I need, but
> when i set autoFields to False, nothing is changing. It's still
> grabbing the foreign keys and causing headaches.
>
> One of the other options of Containable is turn Recursive on and off.
> This works fine, but the boolean of autoFields just won't kick in, or
> I am doing something wrong. Any advice would be greatly appreciated,
> or maybe point me in the direction to get where I need to go!

--

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=.


Reply via email to