Overwrite active_record find?

Christian Kerth
Thu, 29 May 2008 12:17:51 -0000

Hey!

i need to overwrite active record find to synchronize database access

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/.