Bug in association_proxy? getting method_missing...

Using rails 2.1.0

I have a Price class

class Price < ActiveRecord::Base ... end

which is referenced by Offering

class Offering < ActiveRecord::Base ...   belongs_to :special_price, :class_name => 'Price', :foreign_key => "special_price_id" ...   def price_str     self.special_price.price_range_str   end ... end

Unless 'price_str' is called the first time (i.e. on the first request after mongrel startup), I get

"D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/attribute_methods.rb:256:in `method_missing' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:177:in `send' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:177:in `method_missing' app/models/care_offering.rb:41:in `care_price_str' app/views/carehome/new_offering.html.erb:11:in `_run_erb_47app47views47carehome47new_offering46html46erb' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_collection.rb:274:in `method_missing_without_paginate' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:175:in `method_missing' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:175:in `each' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:175:in `send' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:175:in `method_missing' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_collection.rb:274:in `method_missing_without_paginate' vendor/plugins/will_paginate/lib/will_paginate/finder.rb:164:in `method_missing' ..."

This does not happen with this model class class Offering2 < ActiveRecord::Base ...   belongs_to :price ...   def price_str     self.price.price_range_str   end end

THIS ONLY HAPPENS IN development, not in production mode. Is this just a "config.cache_classes = false" side effect? But why then does it only arise in the "indirect referencing scenario"?

Thanks in advance Clemens

Unless 'price_str' is called the first time (i.e. on the first request after mongrel startup), I get

"D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/attribute_methods.rb:256:in `method_missing' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:177:in `send' D:/InstantRails/ruby186-26/lib/ruby/gems/1.8/gems/activerecord-2.1.0/ lib/active_record/associations/association_proxy.rb:177:in `method_missing' app/models/care_offering.rb:41:in `care_price_str' app/views/carehome/new_offering.html.erb:11:in

What's this CareOffering/care_price_str model/method ?

THIS ONLY HAPPENS IN development, not in production mode. Is this just a "config.cache_classes = false" side effect? But why then does it only arise in the "indirect referencing scenario"?

I've seen things like this when I've confused the dependencies system by explicitly requiring application classes.

Fred

Frederick Cheung wrote:

app/models/care_offering.rb:41:in `care_price_str' app/views/carehome/new_offering.html.erb:11:in

What's this CareOffering/care_price_str model/method ?

I shouldn't have mixed p-code with real world stack trace :wink: CareOffering ~ Offering care_price_str ~ price_str

sorry

I've seen things like this when I've confused the dependencies system by explicitly requiring application classes.

could you be more explicit? Do you mean confsuing "has_one" and "belongs_to". Example?

Frederick Cheung wrote:

app/models/care_offering.rb:41:in `care_price_str' app/views/carehome/new_offering.html.erb:11:in

What's this CareOffering/care_price_str model/method ?

I shouldn't have mixed p-code with real world stack trace :wink: CareOffering ~ Offering care_price_str ~ price_str

sorry

Just make sure you haven't removed the problem at the point you transcribed it

I've seen things like this when I've confused the dependencies system by explicitly requiring application classes.

could you be more explicit? Do you mean confsuing "has_one" and "belongs_to". Example?

I mean writing

require 'offering'

when you don't need to (since hitting Offering will require the file for you).

Fred

Frederick Cheung wrote:

I mean writing

require 'offering'

when you don't need to (since hitting Offering will require the file for you).

bingo! :slight_smile: