使用 cakephp 指定递归查找中的字段
假设我有一张食谱,其中有很多成分。
我进行递归查找以获取食谱及其相关成分:
$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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要 ContainableBehavior。
http://book.cakephp.org/1.2/en /The-Manual/Core-Behaviors/Containable.html
You want the ContainableBehavior.
http://book.cakephp.org/1.2/en/The-Manual/Core-Behaviors/Containable.html