【发布时间】:2011-12-20 22:20:50
【问题描述】:
对不起初学者的问题,但我觉得很难理解:
我有资产,在模型中:
class Asset < ActiveRecord::Base
belongs_to :project
belongs_to :image
belongs_to :text
belongs_to :link
belongs_to :video
belongs_to :audio
def self.search(search)
if search
where('title LIKE ?', "%#{search}%")
else
scoped
end
end
end
每种资产类型在其模型中都有自己的表和has_many :assets 定义。我想搜索相应的资产表并获取具有特定标题的项目(然后将它们作为资产列表返回)。它将如何制定查询?我需要使用搜索逻辑吗?
【问题讨论】:
-
我相信这将受益于改变与polymorphic的关系
标签: ruby-on-rails search associations