我有這4個模型通過has_many,belongs_to相互關聯。基本是2(食譜,配料)。另外2個商店基於前兩個存儲額外的信息。 class Recipe
has_many :ingredients, :through => :prescriptions
has_many :prescriptions
end
class Ingredient
has_many
def self.search(search)
if search
find(:all, :conditions => ['name LIKE ?', "%#{search}%"])
end
end
我將如何修改這個功能,所以它首先檢查是否有在name領域search參數完全匹配,如果沒有精確匹配,返回匹配,而不是LIKE ?查詢的結果?