递归模型不会在蛋糕壳中使用 find('all') 或 read(null, id) 加载

发布于 2024-12-11 18:40:34 字数 123 浏览 0 评论 0原文

我无法访问 cakephp shell 中的递归模型。

MyModel 的数据已加载,但未执行联接。当使用相同的 MyModel 和来自控制器的关联时,将执行连接并加载数据。

有人遇到过这个问题吗?

I cannot get access to recursive models in my cakephp shell.

The data of MyModel are loaded, but joins are not performed. When using the same MyModel and associations from a controller, joins are performed and data is loaded.

Does anybody experienced this problem ?

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

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

发布评论

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

评论(2

离去的眼神 2024-12-18 18:40:34

您可以根据所需的数据量将 $recursive 设置为不同的值。想象一下您的应用程序具有属于某个域的组,并拥有许多用户,而这些用户又拥有许多文章

Depth   Description
-1       Cake fetches Group data only, no joins.
0        Cake fetches Group data and its domain
1        Cake fetches a Group, its domain and its associated Users
2        Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles

。然后将其设置为不高于您的需要。让 CakePHP 获取您不会使用的数据会不必要地减慢您的应用程序。另请注意,默认递归级别为 1。

You can set $recursive to different values based on the amount of data you want.Imagine your application features Groups which belong to a domain and have many Users which in turn have many Articles.Then

Depth   Description
-1       Cake fetches Group data only, no joins.
0        Cake fetches Group data and its domain
1        Cake fetches a Group, its domain and its associated Users
2        Cake fetches a Group, its domain, its associated Users, and the Users' associated Articles

Set it no higher than you need. Having CakePHP fetch data you aren’t going to use slows your app unnecessarily. Also note that the default recursive level is 1.

野鹿林 2024-12-18 18:40:34

问题来自我正在使用的 $uses:

在控制器中我有:

$uses = array('MyPlugin.MyModel');

在 shell 中我有:

$uses = array('MyModel');

Cakephp 即使不引用插件也能够找到模型,但它无法找到 HABTM 模型。

The problem was comming from the $uses I was using:

In controller I had:

$uses = array('MyPlugin.MyModel');

In shell I had:

$uses = array('MyModel');

Cakephp was able to find the model even without reference to the plugin, but it failed to find HABTM ones.

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