Sticky Options to Find?


#1

Is there a way to provide “sticky” options to ActiveRecord::Base::Find ?

I’m thinking something with a use model like:

class Function < ActiveRecord::Base
sticky :conditions => “lft > 0”, :order => “lft ASC”
end

Where all subsuquent find operations have those options applied. In
this
case:

Function.find(:all)

Would actually be equivalent to:

Function.find(:all, :conditions => “lft > 0”, :order => “lft ASC”)

And

Function.find(:all, :conditions => “parent_id = 0”)

Would actually be equivalent to:

Function.find(:all, :conditions => “lft > 0 AND parent_id = 0”, :order
=>
“lft ASC”)

Thanks,
Ryan


#2

You might want to read this:

http://www.ruby-forum.com/topic/63128#new

Michael


#3

You can probably override the find method and use with_scope

class Function < ActiveRecord::Base
def self.find(*args)
with_scope(:find => { :conditions => ‘lft > 0’, :order => ‘lft’ })
do
super
end
end
end

-Jonathan.