模型获取连接表
我是 cakephp 的新手。我的客户表有这个
id, product_id, created, modified
,我的产品表有这个
id, label, cost
我想从客户表中选择所有在产品表中有product_id的记录(可能是在id上连接)?
我怎样才能做到这一点
I am new to cakephp. I have table customers with this
id, product_id, created, modified
and my product table has this
id, label, cost
I want to select all the records from customer table which has the product_id in product table (join on id may be)?
How can I do that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该在模型中为要查询的表编写一个 hasMany 关联,然后执行
$this->Model->find('all'...)
查询并确保在您的选项中指定recursive=>1
,以便它将获取您的关联数据。 http://book.cakephp.org/view/1043/hasManyYou should write a hasMany association in your model for the table you would like to query, then do your
$this->Model->find('all'...)
query and make sure in your options you specifyrecursive=>1
so that it will get your associated data. http://book.cakephp.org/view/1043/hasMany