views:

34

answers:

3

In a Rails controller, I'm setting a variable like this:

@users = User.find(:all, :joins => family)

This gives me all the users that have families. What I want is exactly the opposite: all the users that don't have families.

I tried adding:

:conditions=> {:family => nil}

... but got an error.

What's the proper way to do a right outer join?

A: 

Admittedly my Ruby is poor, but I believe when I ran into a similar issue, I was able to filter for NULL using the following

:conditions => "family IS NULL"
Dusty
A: 

If you want to do something other than the default inner join you need to pass a string as the :joins parameter with the sql fragment for the join that you want to do.

Corey
A: 

If family is a related object, you'd want to check if the family_id is null in the conditions clause.

:conditions => "family_id IS NULL"
KarenG