我在一个项目中使用 ruby sequel gem 作为我的 ORM,我想使用以下查询来加载一个 sequel 模型:
SELECT "subject", "addresses", "personal", "read_by", "folder", "created_at", "updated_at", "sent_at", "draft",
--HOW DO I DO THIS IN Sequel?
EXISTS(SELECT COUNT(id) FROM "todos" WHERE reference_email_id = "emails"."id") as "todos"
FROM "emails"
INNER JOIN "email_participants" ON ("email_participants"."email_id" = "emails"."id") WHERE (("user_id" = 124))
在上面的查询中是这个返回布尔结果的子查询:
EXISTS(SELECT COUNT(id) FROM "todos" WHERE reference_email_id = "emails"."id") as "todos"
FROM "emails"
目前,我的 ruby 代码看起来像这样,用于选择除上面概述的布尔表达式之外的所有内容:
Email.inner_join(:email_participants, {email_id: :id})
.where(user_id: query.user_id)
.select_all(:emails)
如何获得包含此 EXISTS 子查询表达式的续集?