Rails - using :include to find objects based on their child's attributes

Posted by adam on Stack Overflow See other posts from Stack Overflow or by adam
Published on 2010-04-19T01:42:55Z Indexed on 2010/04/19 3:43 UTC
Read the original article Hit count: 155

Filed under:
|

I have a sentence and correction model

class Sentence < ActiveRecord::Base
    has_one :correction

class Correction < ActiveRecord::Base
   belongs_to :sentence

and I'm trying find all sentences which don't have a correction. To do this I'm simply looking for corrections which don't exist i.e. whose id = nil. But it is failing and i can't figure out why

 Sentence.find :all, :include => :correction, :conditions => {:correction => {:id => nil}}

Perhaps its the syntax or maybe just the overall approach. Can anyone help?

© Stack Overflow or respective owner

Related posts about activerecord

Related posts about ruby-on-rails