CakePHP:HABTM 未在 habtmDelete 调用上正确执行连接

发布于 2024-10-28 07:59:41 字数 1066 浏览 7 评论 0原文

我们将从 Cake 1.2 升级到 1.3.8,并使用 ExtendedAssociations 行为。

我们遇到的问题之一是我们的 Store 模型,它通过 stores_modulesModule 建立 HABTM 关系。

检索数据固然很好,但迁移到 1.3.8 似乎引入了一个问题,即当我们想要从 Stores 模型中删除 Store 中的所有 Modules

$this->habtmDeleteAll('模块', $this->id);

问题是这会产生以下 SQL 查询(因为它首先选择所有stores_modules,以查看要删除的内容)

stores_modules 选择 StoresModule.module_id AS StoresModule WHERE StoresModule。<代码>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 FROM stores_modules AS StoresModule WHERE StoresModule.store_id = 1 AND Module.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

べ映画 2024-11-04 07:59:41

我不确定我是否理解,但看来您没有正确调用您的模型。如果您需要删除所有关联的模型记录,您可能会执行以下操作:

$this->Store->Modules->deleteAll(array('Store.id' => $id), true, false);

未测试!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文