Re: Overwrite active_record find?

Frederick Cheung
Thu, 29 May 2008 12:26:13 -0000

On 29 May 2008, at 13:17, Christian Kerth wrote:

>
> Hey!
>
> i need to overwrite active record find to synchronize database access
>
You need to say super(*args). alias_method_chain is usually a more
prudent choice for this sort of stuff (and i assume you know that this
won''t accomplish anything if you''re using a pack of mongrels
or
whatever - I suppose it would work if you had a single multithreaded
script, but I''m still not sure what the point would be)

Fred
> i''ve tried the following:
>
> def self.find(*args)
>           begin
>                @@semaphore.synchronize {
>
>
>                        super(args)
>
>
>                }
>            rescue
>                puts "error: "+$!
>                @@semaphore.unlock
>            end
>        end
>
>        def self.find_by_sql(sql)
>
>           begin
>                @@semaphore.synchronize {
>
>
>                      super(sql)
>
>
>                }
>            rescue
>                puts "error: "+$!
>                @@semaphore.unlock
>            end
>        end
>
> I always get an error:
>
> c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
> base.rb:1227:in
> `find_initial'': undefined method `first'' for nil:NilClass
> (NoMethodError)
>        from
> c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
> base.rb:1514:in
> `send''
>        from
> c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/
> base.rb:1514:in
> `find_by_requesttype_and_requeststatus''
>
>
>
> Obviously the dynamic finder methos like
> find_by_equesttype_and_requeststatus doesn''t work.
>
> Any clues to fix this?
>
> Thx
> --
> Posted via http://www.ruby-forum.com/.