如何在 rails 中使用 Mailboxer 让用户收到未读消息
How to get users with unread message receipts with Mailboxer in rails
我正在尝试根据 "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" = WHERE "receipts"...
^
: SELECT DISTINCT users.id FROM "users" INNER JOIN "mailboxer_receipts" ON "mailboxer_receipts"."receiver_id" = "users"."id" AND "mailboxer_receipts"."receiver_type" = 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" = 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 状态时,一切都失败了。我已阅读 this thread 并且似乎正在使用推荐的格式,但仍然无法正常工作。我错过了什么吗?
改为
user_ids = User.
joins(:receipts).
where("mailboxer_receipts.is_read" => false}).
select('DISTINCT users.id').
map(&:id)
或
user_ids = User.
joins(:receipts).
where(:mailboxer_receipts => {:is_read => false}).
select('DISTINCT users.id').
map(&:id)
我正在尝试根据 "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" = WHERE "receipts"...
^
: SELECT DISTINCT users.id FROM "users" INNER JOIN "mailboxer_receipts" ON "mailboxer_receipts"."receiver_id" = "users"."id" AND "mailboxer_receipts"."receiver_type" = 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" = 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 状态时,一切都失败了。我已阅读 this thread 并且似乎正在使用推荐的格式,但仍然无法正常工作。我错过了什么吗?
改为
user_ids = User.
joins(:receipts).
where("mailboxer_receipts.is_read" => false}).
select('DISTINCT users.id').
map(&:id)
或
user_ids = User.
joins(:receipts).
where(:mailboxer_receipts => {:is_read => false}).
select('DISTINCT users.id').
map(&:id)