1

Suppose I need to check if a certain property is not set.

I imagine something like this but It doesn't work.

@users = User.find_all_by_role(["role = ?",nil])

I tried some other variants with no luck.

I guess this should be pretty straightforward.

Thank you!

3 Answers 3

1

Using ActiveRecord's pre-3.0 syntax:

@users = User.find(:all, :conditions => { :role => nil })

After 3.0 you can write:

@users = User.where(:role => nil)
Sign up to request clarification or add additional context in comments.

Comments

0

Try: @users = User.find(:all, :conditions=>'role is null')

1 Comment

Thank you, there's a cleaner way above.
0
@users = User.where(:roles => nil).all

There's no need to break into SQL for this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.