I figured this out by creating a belongs_to relation to the last post in my User class.
belongs_to :last_message, :class_name => 'Message'
I set my last message to after_create in the Message class. Then my scope is as follows:
scope :filter_by_last_messages, lambda { |value|
joins(:last_message).where("content = ?", value)
}
source
share