CakePHP hasAndBelongsToMany (HABTM) Delete Joining Record
Posted
by Jason McCreary
on Stack Overflow
See other posts from Stack Overflow
or by Jason McCreary
Published on 2010-05-15T02:53:45Z
Indexed on
2010/05/15
5:14 UTC
Read the original article
Hit count: 230
I have a HABTM relationship between Users and Locations. Both Models have the appropriate $hasAndBelongsToMany
variable set.
When I managing User Locations, I want to delete the association between the User and Location, but not the Location. Clearly this Location could belong to other users. I would expect the following code to delete just the join table record provided the HABTM associations, but it deleted both records.
$this->Weather->deleteAll(array('Weather.id' => $this->data['weather_ids'], false);
However, I am new to CakePHP, so I am sure I am missing something. I have tried setting cascade to false and changing the Model order with User, User->Weather, Weather->User. No luck.
Thanks in advance for any help.
© Stack Overflow or respective owner