1

I am using Rails 2.3.10. I have models called Stream, Buzz, and BuzzDigest. There is an association, buzz has_many :streams. There is another association, buzz has_one :digest. Sometimes, buzz.digest is nil. How do I write a query for Stream that would filter out streams where the stream's buzz's digest is nil?

This isn't correct syntax, but might be close to what I want:

Stream.find( :all, :conditions => "buzz_id.digest IS NOT NULL" )
prusswan
  • 6,853
  • 4
  • 40
  • 61
Eric
  • 1,235
  • 2
  • 13
  • 26

1 Answers1

0

Since BuzzDigest is an Object, and not a DB field or attr_accessor, you may want to fix the fact that buzz.digest CAN be nil in the first place within the design of your app.

If you balk at that, quick thought has something like:


Stream.includes[:buzzes, :buzz_digests].group(:id)

assuming the right schema. SO question may have some hints too.

Community
  • 1
  • 1
pjammer
  • 9,489
  • 5
  • 46
  • 56