Wednesday, January 28, 2009

Save + HABTM != beforeDelete()

Scenario:

Members <- HABTM -> Webpages.

When a member edits their info there is also a big list of different
webpages they can check/uncheck ... when they go to save it will
delete the joins then re-add them. When it deletes them, it does so in
a way that `beforeDelete()` nor `afterDelete()` are called.

/cake/libs/model/model.php lines 1315 - 1330:

if ($this->hasAndBelongsToMany[$assoc]['unique']) {
$associationForeignKey = "{$join}." . $this->hasAndBelongsToMany
[$assoc]['associationForeignKey'];
$oldLinks = Set::extract($links, "{n}.{$associationForeignKey}");
if (!empty($oldLinks)) {
$conditions[$associationForeignKey] = $oldLinks;
$db->delete($this->{$join}, $conditions);
}
}

if (!empty($newData)) {
foreach ($newData as $data) {
$data[$this->hasAndBelongsToMany[$assoc]['foreignKey']] = $id;
$this->{$join}->create($data);
$this->{$join}->save();
}
}


------

My question is: why? What do I do if I want to trigger a `beforeDelete
()` call?

Logically I would assume that creating a join-table model (in my
scenario MemberWebpage) and throwing it in there would solve that, but
obviously from the above code this would never get called ... so ...
is this intentional or a bug??
--~--~---------~--~----~------------~-------~--~----~
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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: