I'm using awesome_nested_set for building mail conversations. I have two mailboxes (Inbox and Sent) and now I want to build a proper conversation view. The main goal is select roots that have any descendants in target mailbox and root's last leaf for view on the conversation's list page. My message model:
class Message
belongs_to :mailbox
acts_as_nested_set
...
end
E.g. If I selected Inbox, I would want to select: roots those have any message with that belongs to Inbox. How can I do with select? Do I need to build a Conversation model that would have message_id, mailbox_id, unique_thread_number for this?
I'd go reversely... Select messages and then get their roots.
In the above logic I don't use any filtering, this means at start I select ids for all
messagesininbox... I guess you will have to add some filtering (whereclause) to narrow results down.Then, you get the
rootsfor those messagesThen, you get the
leaf_idsof those rootsYour desired viewable messages will be the
leaves.Updated Now that I see it, you can do it with one less step (if you don't need the roots themselves):