I’m sure you all know how to use the :conditions attribute when using ActiveRecord:
User.find(:all, :conditions=>['active = ?', true])
And you may even use associations this way:
User.find(:all, :include=>[:photos], :conditions=>['photos.removed = ? and users.active = ?', false, true])
But did you know that you can do this easier through hashes?
User.find(:all, :conditions=>{:active=>true}) User.find(:all, :include=>[:photos], :conditions=>{'photos.removed'=>false, 'users.active'=>true})
Nothing special there, but I thought it was pretty cool. One thing you have to remember when using associations, is to include that model.
Tags: activerecord, association, conditions, hash, rails

July 2nd, 2009 at 12:48 pm
check this out…
this is mine…
February 5th, 2010 at 1:18 am
Joe…
Check out my domain sometime….