CakePHP: HABTM not performing join properly on habtmDelete call
We are upgrading from Cake 1.2 to 1.3.8,开发者_JS百科 and using the ExtendedAssociations behavior.
One of the problems we are having, is in our Store model, which has a HABTM relationship to Module via stores_modules.
Retrieving the data is all good, but one issue moving to 1.3.8 seems to have introduced is that when we want to delete all Modules from the Store - in the Stores model
$this->habtmDeleteAll('Module', $this->id);
The problem is that this produces the following SQL query (as it is SELECTING all stores_modules first, to see what to delete)
SELECT
StoresModule
.module_id
FROMstores_modules
ASStoresModule
WHEREStoresModule
.store_id
= 1 ANDModule
.system_default
= 0
_
2011-03-29 18:27:46 Warning: Warning (512): SQL Error: 1054: Unknown column 'Module.system_default' in 'where clause' in [/usr/lib/cakephp_1.3.8/cake/libs/model/datasources/dbo_source.php, line 684]
So it appears the problem is that the above SQL statement is not adding the JOIN to the modules table.. hence it cannot fine Module
.system_default
Any help on this would be great, it's really got me stumped :)
Chris.
I'm not totally sure I understand, but it appears you are not calling your models correctly. If you need to delete all associated model records, you would probably do something like this:
$this->Store->Modules->deleteAll(array('Store.id' => $id), true, false);
NOT TESTED!
精彩评论