使用ActiveRecord,如何根据关联的属性执行LIKE查询?具体地说,我正在寻找与多态关联一起工作的东西。
class Invoice < ActiveRecord::Base
has_one :private_note, class_name: '::Note', as: :noteable,
conditions: {label: 'private'}
has_one :public_note, class_name: '::Note', as: :noteable,
conditions: {label: 'public'}
end
class Note < ActiveRecord::Base
belongs_to :noteable, polymorphic: true
validates :content, :presence: true
end我要查找其private_note具有包含单词"friendly“的content列的发票。
发布于 2013-05-24 20:43:19
使用#merge
这可以使用.merge方法来完成。
Invoice.joins(:private_note).merge(Note.where("content LIKE ?", '%friendly%'))https://stackoverflow.com/questions/16735268
复制相似问题