Parent
にはという属性を持つChild
がたくさんあると仮定して、status_id:1
を持たないすべての子供を探したいと思います。換言すれば、status_id
はnil
であってもよいし、異なる値であってもよい。しかし、私はいくつかの興味深い行動見ている:Rails ActiveRecordは属性が与えられた値ではないところを見つけます
Parent.find(1).childs.where(status_id:nil)
=> #<ActiveRecord::AssociationRelation [#<Child id: 1, status_id: nil ...>]
Parent.find(1).childs.where.not(status_id:1)
=> #<ActiveRecord::AssociationRelation []>
あなたが書くことができますように: 'Parent.find(1).childs.where( "!STATUS_ID = 1")'または 'Parent.find(1).childs.where(" status_id!=? "、1)' –
@KhanhPhamも動作しません....まだ取得 '=># ' –
james