views:

27

answers:

1

this is a follow up to a previous question i asked. i am having trouble getting a query to work that has a variety of conditions for nested models.

user has_one avatar
user has_one profile
avatar belongs_to user
profile belongs_to user

and i am actually able to get this to work...

Avatar.find(:all, :include => {:user => :profile}, :conditions => {:users => {:profiles => {:description => 'foo'}}})

however i want it to return an avatar if the profile.description is NOT NULL.

Avatar.find(:all, :include => {:user => :profile}, :conditions => {:users => {:profiles => "profiles.description IS NOT NULL"}})

so when i change the query to follow the SQL syntax rather than the railsesque syntax, i get an error "No such column user.profiles"

it doesnt seem to matter what statement i use for "profiles.description IS NOT NULL", the error is the same. it must be something else with that structure.

+1  A: 

Try this:

Avatar.all(:include => {:user => :profile}, 
  :conditions => ["profiles.description IS NOT NULL"])

You have to use the conditions array for such queries.

KandadaBoggu