【发布时间】:2013-01-21 10:00:28
【问题描述】:
我有两个实体 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),我想写另一个范围在comments 中搜索posts(msg)。
这个怎么写?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 scope arel rails-activerecord