我要按多个表进行搜索
我的模式是
fields => :id
class Manufacturer
has_many :brands, dependent: :destroy
has_many :translations, class_name: 'ManufacturerTranslation', dependent: :destroy
end
fields => :id,:manufacturer_id, :locale ,:name
class ManufacturerTranslation
belongs_to :manufacturer
end
fields => :id, :manufacturer_id
class Brand
belongs_to :manufacturer, inverse_of: :brands
has_many :translations, class_name: 'BrandTranslation', dependent: :destroy
end
fields => :id,:brand_id, :locale ,:name
class BrandTranslation
belongs_to :brand
end
我必须搜索BrandTranslation
名称和/或ManufacturerTranslation
名称
我尝试过
joins(:translations,:manufacturer_translations).
where('brand_translations.name ILIKE ? or manufacturer_translations.name = ?"', "%#{query}%", "%#{query}%")
如何编写适当的sql或activerecord查询?