我有两个实体Posts
,Comments
关联如下
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
现在scope :search
只搜索,comments(msg)
我想写另一个范围来搜索posts(msg)
。comments
这个怎么写?