Forum: Ruby on Rails Sticky Options to Find?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2006-06-02 20:30
(Received via mailing list)
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
Michael T. (Guest)
on 2006-06-02 21:08
(Received via mailing list)
You might want to read this:

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

Michael
Jonathan V. (Guest)
on 2006-06-03 06:28
(Received via mailing list)
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.
This topic is locked and can not be replied to.