Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unread in Trash #235

Open
zombiebsas opened this issue Feb 2, 2014 · 1 comment
Open

Unread in Trash #235

zombiebsas opened this issue Feb 2, 2014 · 1 comment

Comments

@zombiebsas
Copy link

When I execute this from the console it returns the same number of conversations:

User.find(1).mailbox.trash(:is_read => true) 

vs:

User.find(1).mailbox.trash(:is_read => false)

Or even:

User.find(1).mailbox.trash(:unread => true) 

vs:

User.find(1).mailbox.trash(:unread => false)

When I use :unread => true I get this SQL from the console:

SELECT DISTINCT conversations.* FROM "conversations" 
INNER JOIN "notifications" ON "notifications"."conversation_id" = "conversations"."id" AND "notifications"."type" IN ('Message') 
INNER JOIN "receipts" ON "receipts"."notification_id" = "notifications"."id" 
WHERE "receipts"."trashed" = 't' 
AND "receipts"."deleted" = 'f' 
AND "notifications"."type" = 'Message' 
AND "receipts"."receiver_id" = 1 
AND "receipts"."receiver_type" = 'User' 
AND "receipts"."is_read" = 'f' 
ORDER BY conversations.updated_at DESC

In the last condition it's clear that the SQL is filtering by is_read = 'f'
Am I doing something wrong or this is a bug? I would like to be able to count how many unread messages I trashed.

Thanks.
-A.

@w3irdrobot
Copy link
Contributor

You are getting everything from conversations here. So my guess is they you have read and unread receipts trashed from the same conversations. So it is returning the same conversations. This isn't returning the individual receipts. Try something like below:

User.find(1).receipts.trash.is_unread

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants