On Jan 16, 2009, at 4:54 PM, Wes Gamble wrote:

>
> Frederick Cheung wrote:
>> On 16 Jan 2009, at 20:44, Wes Gamble wrote:
>>
>>> When the Invoice class is loaded, all of its class level association
>>> directives are executed.  When it hits the one that doesn't have a
>>> backing table, it fails.
>>
>> So it's at the point where the class (not the data) is loaded that  
>> the
>> problem occurs ? You might be in a tight spot then because it's going
>> to be hard to remove the association before the class exists.
>
> Actually, the class needs to exist and I just need to temporarily  
> remove
> the association.

Can you show us the has_many part of your Invoice class?

Product is a model in one of my client projects.  I can do:
$ script/console
Loading development environment.
irb> Product
=> Product
irb> class Product; has_many :foobars; end
=> [:build_to_foobars]
irb> p=Product.find(:first)
=> #<Product:0x3edb0e0 @attributes={...}>
irb> p.methods.include?('foobars')
=> true
irb> p.foobars
NameError: uninitialized constant Product::Foobar

Notice that there is no error when the:
   has_many :foobars
gets processed.  When I find a product, it has a foobars method, but  
it doesn't work.

Perhaps you are defining your association is a way that causes pre- 
mature loading of the associated model?

>
>> define a new class Invoice < ActiveRecord::Base inside your fixture
>> generation code. if you don't need any of Invoice's methods then
>> you're fine with just this
>
> I need to be able to do a find on Invoice, which is why I have the
> problem in the first place, so this probably won't work.
>
>> Override ActiveRecord::Base.has_many to check if self is invoice and
>> the association name is the bad one. if it is, do nothing. if not let
>> the normal code run.
>
> This may work and I will give it a shot.  Thanks for the idea.
>
> Wes

'Cause this seems like a lot of work that might not even be necessary.

-Rob

Rob Biedenharn          http://agileconsultingllc.com
[email protected]



--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to