CakePHP:HABTM 未在 habtmDelete 调用上正确执行连接
我们将从 Cake 1.2 升级到 1.3.8,并使用 ExtendedAssociations 行为。
我们遇到的问题之一是我们的 Store 模型,它通过 stores_modules 与 Module 建立 HABTM 关系。
检索数据固然很好,但迁移到 1.3.8 似乎引入了一个问题,即当我们想要从 Stores 模型中删除 Store 中的所有 Modules 时
$this->habtmDeleteAll('模块', $this->id);
问题是这会产生以下 SQL 查询(因为它首先选择所有stores_modules,以查看要删除的内容)
从
stores_modules
选择StoresModule
.module_id
ASStoresModule
WHEREStoresModule
。<代码>store_id = 1 和模块
。system_default
= 0
_
2011-03-29 18:27:46 警告:警告(512):SQL 错误:1054:[/usr/lib/cakephp_1.3.8/cake/ 中的“where 子句”中的未知列“Module.system_default” libs/model/datasources/dbo_source.php,第 684 行]
所以看来问题是上面的 SQL 语句没有将 JOIN 添加到 modules 表中。因此它无法精细 Module
.system_default
对此的任何帮助都会很棒,这真的让我难住了:)
克里斯。
We are upgrading from Cake 1.2 to 1.3.8, 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定我是否理解,但看来您没有正确调用您的模型。如果您需要删除所有关联的模型记录,您可能会执行以下操作:
未测试!
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:
NOT TESTED!