记录:通过相关连数据筛选(未作出功能)

profiles = Subject.where("name LIKE ?", "%#{params[:search]}%").map(&:profiles)

class Owner < ActiveRecord::Base
    has_many :dogs
end

class Dog < ActiveRecord::Base
    belongs_to :owner
end
 def self.search(search)
    if search
      joins(:owner).where('dogs.name LIKE ? or owners.name LIKE ?', "%#{search}%", "%#{search}%")
    else
      find(:all)
    end
  end

1 2