我正在尝试根据他们的“is_read”邮箱收据获取所有未读用户消息的列表。我一直在尝试使用以下行来做到这一点:
user_ids = User.
joins(:receipts).
where(receipts: {is_read: false}).
select('DISTINCT users.id').
map(&:id)
这是我得到的错误:
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: missing FROM-clause entry for table "receipts"
LINE 1: ...D "mailboxer_receipts"."receiver_type" = $1 WHERE "receipts"...
^
: SELECT DISTINCT users.id FROM "users" INNER JOIN "mailboxer_receipts" ON "mailboxer_receipts"."receiver_id" = "users"."id" AND "mailboxer_receipts"."receiver_type" = $1 WHERE "receipts"."is_read" = 'f'
/Users/lorenzsell/DEV/Heartbeat-pods/app/jobs/schedule_send_notifications_job.rb:10:in `perform'
/Users/lorenzsell/DEV/Heartbeat-pods/lib/tasks/email_tasks.rake:5:in `block (2 levels) in <top (required)>'
-e:1:in `<main>'
PG::UndefinedTable: ERROR: missing FROM-clause entry for table "receipts"
LINE 1: ...D "mailboxer_receipts"."receiver_type" = $1 WHERE "receipts"...
^
/Users/lorenzsell/DEV/Heartbeat-pods/app/jobs/schedule_send_notifications_job.rb:10:in `perform'
/Users/lorenzsell/DEV/Heartbeat-pods/lib/tasks/email_tasks.rake:5:in `block (2 levels) in <top (required)>'
我可以毫无问题地调用 User.joins(:receipts) ,但是一旦我尝试获取 is_read 状态,一切都会失败。我已阅读此线程并且似乎正在使用推荐的格式,但仍然无法使其正常工作。我错过了什么吗?