使用 cakephp 指定递归查找中的字段

发布于 2024-10-10 06:07:24 字数 345 浏览 0 评论 0原文

假设我有一张食谱,其中有很多成分。

我进行递归查找以获取食谱及其相关成分:

$this->Recipe->find('all', array('fields' => array('id','title','description')));

在这里,我可以使用“fields”属性来指定我只希望它返回 id、标题和描述。然而,尽管如此,cakephp 仍然返回成分表中的所有列。

我如何告诉 cakephp 我只想要成分表的 id 和 name 字段?

顺便说一句,成分模型是“成分”,表是成分,聚合表是recipes_ingredients。

Suppose I have a table Recipe that hasmany ingredients.

I do a recursive find to grab recipes with their associated ingredients:

$this->Recipe->find('all', array('fields' => array('id','title','description')));

Here I can use the 'fields' attribute to specify that I only want it to return id, title, and description. However, despite this, cakephp still returns ALL columns from the ingredients table.

How do I tell cakephp that I only want ingredient table's id and name fields?

btw ingredient model is "Ingredient" and the table is ingredients, and the aggregation table is recipes_ingredients.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文