Re: Accessing Parent Record Data

2010-01-14 Thread Alexandru Ciobanu

On 1/14/2010 8:08 AM, emptywalls wrote:

That did it! Thanks so much! Took a little figuring out, but I see
what ya did there.
   

After you get a hang of the Containable behavior you'll never use 
anything else.
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Accessing Parent Record Data

2010-01-13 Thread emptywalls
That did it! Thanks so much! Took a little figuring out, but I see
what ya did there.
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Accessing Parent Record Data

2010-01-13 Thread emptywalls
No, that didn't work. I'm looking at the array thats returned, it
appears to be empty.
Array
(
[Song] => Array
(
[id] => 2394
[title] => Gimme Shelter
)

[ParentSong] => Array
(
[id] =>
)
[Artist] => Array
(
[0] => Array
(
[id] => 770
[name] => Rolling Stones
[ArtistsSong] => Array
(
[id] => 2424
[artist_id] => 770
[song_id] => 2394
)

)

)

)

Here's the query:
SELECT `Song`.`id`, `Song`.`title`, `Song`.`subtitle`,
`ParentSong`.`id` FROM `songs` AS `Song` LEFT JOIN `songs` AS
`ParentSong` ON (`Song`.`parent_id` = `ParentSong`.`id`) WHERE 1 = 1
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Accessing Parent Record Data

2010-01-13 Thread emptywalls
You make it sound so easy! I will give this a try tonight, and then
report back. Thank you so much for the response.
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Re: Accessing Parent Record Data

2010-01-13 Thread Alexandru Ciobanu

Use containable in your song model:

var $actsAs = array('Containable');

 var $belongsTo = array(
'ParentSong' => array(
'className' => 'Song',
'foreignKey' => 'parent_id',
));

When retrieving records contain ParentSong.

E.g.

$this->find('all', array('contain' => array('ParentSong')));

http://book.cakephp.org/view/474/Containable
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en


Accessing Parent Record Data

2010-01-12 Thread emptywalls
I am building a list of songs, and the songs can be original songs, or
cover versions of other songs. If the song is a cover version, I want
to be able to get to the original artist, along with the title of the
song and the cover artist.

Here are the tables/fields I'm working with:
- songs
id
parent_id
title

- artists_songs
id
artist_id
song_id

- artists
id
name

There is a hasAndBelongsToMany relationship between the artists and
songs tables because a song can have many artists. Obviously artists
can have many songs. When a cover version is added, the parent_id
contains the id of the original song.

This is how I would like to be able to display them:
These are original songs:
Rolling Stones - Gimme Shelter
Kate Bush - Running Up That Hill

These are cover versions:
Sisters of Mercy - Gimme Shelter (Rolling Stones Cover)
Placebo - Running Up That Hill (Kate Bush Cover)

I have been struggling with how to make this work, any advice or tips
to push me in the right direction would be much appreciated.
Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en