I have a situation where I need to have all find methods on a object automatically scoped to a certain condition, ie
MyObject.with_scope( :find => { :conditions => "x = 'foo'" }) where 'foo' is something that is found in the user session.
obviously the model is not going to know anything about the session so i can't do something like
class MyObject < ActiveRecord::Base
alias_method :orig_find, :find def self.find(*args) with_scope { :find => { :conditions => ["x = ?", @current_user.x] }) orig_find(*args) end end end
(not even sure if that would be even close to how it MIGHT be implemented).
i other words, i want to get around having to do
mo = MyObject.find_by_x(x) or having to specify the conditions ALL the time
any assistance would be appreciated.
Chris