has and belongs to many - CakePHP hasAndBelongsToMany (HABTM) Delete Joining Record -


I have a HABT connection between user and location. Both models have the appropriate $ and billionshome variable Set up.

When I manage user space, I want to delete the connection between the user and the location, but not the location. This location can obviously be for other users. I hope that only the HABT Association has to delete the following code to delete the host table record provided, but it has removed both records.

  $ this-> Weather- & gt; All deleted (array ('weather id =' => $ this-> data ['weather_ids'], incorrect);  

However, I'm new to kHHP So, I'm sure I'm missing something, trying to set the waterfall to flag and change the model order with user, user-> weather, weather-> user. No luck.

Thanks in advance for any help.

It is not certain how M The same is related to your model, so I will go with just the conventional names, the location user is the table joining it. This is the ID $ id And all associations should be removed with any place:

  $ this-> user - & gt; location-user- & gt; delete all (Arrays ('LocationsUser.user_id' = & Gt; $ id), incorrect);  

Also keep in mind that you are missing a closing bracket in your cod. Ipet.


Comments