i have an Order model and a table for addresses. i was trying to use
single table inheritance so that i can store the addresses in the same
table.
here is my order model:
class Order < ActiveRecord::Base
has_one :billing_address, :class_name =>
''BillingAddress'', :foreign_key =>
''order_id''
has_one :shipping_address, :class_name =>
''ShippingAddress'', :foreign_key =>
''order_id''
end
and the address model:
class Address < ActiveRecord::Base
end
class BillingAddress < Address
belongs_to :order, :class_name => ''Order''
end
class ShippingAddress < Address
belongs_to :order, :class_name => ''Order''
end
everything appears to be working fine, unless i try and do something
like this:
my_order.billing_address.create(...)
i get this in the console:
NoMethodError: You have a nil object when you didn''t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.create
however, if i create an address this way:
BillingAddress.create(....... :order => my_order) it works fine. i can
even use order.billing_address and it will pull up the right record.
is this right, or did i set up the relationships wrong?
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---