查找诸如“NOT EXISTS”之类的条件
我的数据库中有 2 个表...
Entita
id int(11)
描述 varchar(50)
.....
公共对象
....
model varchar(50) 我需要的模型(在本例中是'Entita')
model_id int(11)
我想进行如下查询:选择实体。* 来自实体 where NOT EXISTS (select * from publicobjects where publicobjects.model = 'Entita' and publicobjects.model_id = entita.id)
如何在不使用自定义查询的情况下使用 Cakephp 的模型函数来执行此操作?
谢谢
I have 2 tables in my db...
Entita
id int(11)
descrizione varchar(50)
.....
Publicobjects
....
model varchar(50) the model I need (in this case 'Entita')
model_id int(11)
I would like to make a query like this:select entita.*
from entita
where NOT EXISTS (select * from publicobjects where publicobjects.model = 'Entita' and publicobjects.model_id = entita.id)
How can I do this with the model functions of Cakephp without use custom query?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您正在尝试从 Entita 表中查找不在 Publicobjects 表中的行。假设这是正确的,下面是 MySQL 查找它的 SQL 查询:
要使其与 CakePHP 的模型一起工作,需要执行几个步骤。我对你的型号名称做了一些假设,但我可能是错的,而且这些很容易修复。
首先将其添加到 Entita 模型中:
现在,您可以检查 Publicobjects 表中缺少的条目,如下所示:
I believe you're trying to find rows from the Entita table that are not in the Publicobjects table. Assuming that is correct, here is the SQL query for MySQL to find it:
To make this work with CakePHP's models takes a couple of steps. I've made some assumptions about your model names, but I could be wrong and those are easy to fix.
First add this to the Entita model:
Now, you can check for entries that are missing in the Publicobjects table like this: