I want to display sent messages by the user. Problem is drafts and sent message contents are stored in the same table, so I want to put a condition on the following association from user.rb
has_many :sent_messages, :class_name => "Message", :foreign_key => "user_id", :conditions => [#it has been sent!]
I thought of using a is_sent method from message.rb
def is_sent
current_user.drafts.find_by_message_id(:first, self.id).empty?
end
How can i call this method in the :condition of my association?
Would it be preferable to use a column in my Message table specifying if the stored message has been sent or not?
Thanks!
I would add a boolean
sentcolumn toMessage, and use this condition in thehas_many:This would also give you the function
sent?inMessage, eliminating youris_sentfunction. Note that using a question mark like that in function names in Ruby is common practice, andis_is frowned upon.