I've recently implemented an "active" flag on several of my models in a very large codebase, and I'd rather not have to go back and change every Model.find() instance to specify the new conditions - {:active => true}
So I was thinking: how can I make the model itself automatically append that to the conditions passed in?
I tried this, but to no avail: (in app/models/model.rb) Class Something < ActiveRecord::Base
# ...
# Overwriting the find method to exclude anything NOT active. def find if @conditions.blank? @conditions = "active = true" else @conditions = @conditions + " AND active = true" end
super end
# ... end
Unfortunately, my tests didn't work. I went in and set the first row in my somethings table to be inactive, but find(:first) still returned it.
I don't see an activerecord call back like "before_find" or something (though I've read about, but can't seem to find documented, an "after_find").
Does anyone know how I can do this, or is manually editing every single Model.find instance the only way?