在 CakePHP 中创建临时表并将其作为模型加载

发布于 2024-11-01 21:16:28 字数 403 浏览 3 评论 0原文

我的计划是使用 $this->Model->query(); 创建一个临时表方法然后将其加载为模型,但我收到错误“缺少数据库表”。将调试打开到第二级表明临时表已成功完全创建,但由于某种原因,当我尝试将其作为模型加载时,它不起作用。看起来 cake 甚至没有尝试查看该表是否存在,因为没有显示“SHOW FULL COLUMNS FROM ...”查询。不知道如何强制 cake 检查其存在。

$tmpModel = 'tempModel';
$tmpTable = 'temp_models';

$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
$this->loadModel($tmpModel);

提前致谢。

My plan is to create a temporary table using the $this->Model->query(); method then load it as a Model but I'm getting an error staying "Missing Database Table". Turning on debug to level two shows that the temporary table is success fully created but for some reason, when I try and load it as a model it doesn't work. It looks like cake doesn't even try to see if the table exists as there is no "SHOW FULL COLUMNS FROM ...' query being displayed. Not sure how to force cake to check for its existence.

$tmpModel = 'tempModel';
$tmpTable = 'temp_models';

$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
$this->loadModel($tmpModel);

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

小…红帽 2024-11-08 21:16:28

$tmpModel = 'TempModel'; // CamelCase

也尝试一下,ClassRegisty::init($tmpModel);

最终问题可能是缓存。但不这么认为

$tmpModel = 'TempModel'; // CamelCase

also try, ClassRegisty::init($tmpModel);

final issue may be cache. but dont think so

扭转时空 2024-11-08 21:16:28

好吧,环顾四周后,我找到了一个可行的解决方案。
问题是 Cake 已经在页面加载时加载了模型缓存,因此将它们用作表是否存在的引用。为了解决这个问题,我使用了“App::import('Model', $tmpModel);”它创建了新的 modelCache,允许 loadModel 脚本成功运行。

$tmpModel = 'tempModel';
$tmpTable = 'temp_models';

$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
App::import('Model', $tmpModel);
$this->loadModel($tmpModel);

无论如何,谢谢

Ok, after looking around a bit I have found a solution that works.
The problem was that Cake had already loaded the models caches at page load so used them as reference to the existence of a table. To resolve this problem I used "App::import('Model', $tmpModel);" which created the new modelCache allowing the loadModel script to run successfully.

$tmpModel = 'tempModel';
$tmpTable = 'temp_models';

$this->Model->query('CREATE TEMPORARY TABLE `'.$tmpTable ... );
App::import('Model', $tmpModel);
$this->loadModel($tmpModel);

Thanks anyway

左耳近心 2024-11-08 21:16:28

经过一个小时的谷歌搜索后..终于找到了一种将模型放在临时表上的方法,它的工作原理就像一个魅力
http://web2.0goodies.com/博客/未分类/mysql-temporary-tables-and-cakephp-1-3/

After doing google for an hour .. finally found a way to have Model on Temporary table and it works like a charm
http://web2.0goodies.com/blog/uncategorized/mysql-temporary-tables-and-cakephp-1-3/

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