Hi, is it possible to override Active Record find() in a class that inherits Active Record? eg. def find super <blah blah> end I''ve tried it and it doesn''t seem to work! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
It can be overridden, but it depends on your requirement. Do you just want to process a result_set returned from the super? Or do you want to pass additional options to the super? Or do you want to rewrite it completely? It is a bit difficult say since the requirement is unclear. Long "Lee" wrote:> > Hi, is it possible to override Active Record find() in a class that > inherits Active Record? > > eg. > > def find > super > <blah blah> > end > > I''ve tried it and it doesn''t seem to work! >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Find is a class method. Your example below creates an instance method called find. To override the AR find class method do something like this: def ClassName.find(*args) super(*args) end On 9/8/06, Lee <lee_longmore-/E1597aS9LT10XsdtD+oqA@public.gmane.org> wrote:> > > Hi, is it possible to override Active Record find() in a class that > inherits Active Record? > > eg. > > def find > super > <blah blah> > end > > I''ve tried it and it doesn''t seem to work! > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Hi Lee -- On 8-Sep-06, at 3:58 PM, Lee wrote:> Hi, is it possible to override Active Record find() in a class that > inherits Active Record? > > def find > super > <blah blah> > end > > I''ve tried it and it doesn''t seem to work!Yes, it''s possible... the reason it''s not working for you is because find is a class method, but you''ve written an instance method. Try: def self.find end instead. /Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 8-Sep-06, at 6:04 PM, Aaron Baldwin wrote:> def ClassName.find(*args) > super(*args) > endActually, super''s default behaviour is to slurp up all the args that came into the method in the first place, so the argument is superfluous. See this post for an example of overriding find to set a default order for a model. http://groups.google.com/group/rubyonrails-talk/msg/5ef476cfdd0b3797 /Jeff --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---