All -
I'm trying to wrap my brain around the HABTM 'with' or 'auto-
with' (I've seen this term?) relationship. I think I've got it to a
degree, but I need some help. I have the following:
Site hasOne Prospectingplaylist (dependent => true)
Prospectingplaylist belongsTo Site
Prospectingplaylist hasAndBelongsToMany Clip (my definition
follows...)
var $hasAndBelongsToMany = array(
'Clip' => array('className' => 'Clip',
'joinTable' =>
'clips_prospectingplaylists',
'with' =>
'ClipsProspectingplaylist',
'foreignKey' =>
'prospectingplaylist_id',
'associationForeignKey' =>
'clip_id',
Clip hasAndBelongsToMany Prospectingplaylist (same as above except
reverse also has 'with' specified as above)
I also have defined the 'with' model: ClipsProspectingplaylist in the
clips_prospectingplaylist.php model file.
The reason I've done the 'with' modeling is so I can have a 'position'
column in the join table (clips_prospectingplaylists table), and order
by this column.
When I delete a Site with Site->delete() it deletes everything as
expected but also does this, which I didn't expect:
DELETE FROM `clips_prospectingplaylists` WHERE
`clips_prospectingplaylists`.`clip_id` = 7
Why is it whacking everything with the associated clip_id? Why not
just this:
DELETE FROM `clips_prospectingplaylists` WHERE
`clips_prospectingplaylists`.`prospectingplaylist_id` = 23
It does on to delete the prospectingplaylist as expected:
DELETE FROM `prospectingplaylists` WHERE `prospectingplaylists`.`id` =
23
Now, I can prevent the deletion of all rows with clip_id=7, by putting
this in the ClipsProspectingplaylist model:
function beforeDelete(){
$this->unbindModel( array('belongsTo' =>
array('Clip','Prospectingplaylist')) );
}
I believe what I could do now is create a function in the
ClipsProspectingplaylist model that deletes the join table records
WHERE `clips_prospectingplaylists`.`prospectingplaylist_id` = 23.
Then call this function from the Prospectingplaylist beforeDelete()
callback.
Does this seem right? Am I missing something?
Thanks for any insight.
Best regards,
Jeremy
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---