I have two entities Posts
and Comments
associated as follows
class Post < ActiveRecord::Base
attr_accessible :title, :msg
has_many :comments
end
class Comment < ActiveRecord::Base
attr_accessible :msg
belongs_to :post
scope :search, lambda { |msg| where(arel_table[:msg].matches('%#{msg}%'))}
end
The scope :search
now search only for comments(msg)
, I want to write another scope to search for posts(msg)
in comments
.
How to write this?