Hi,

Is there a recommended way to handle the following deviance from the
standard polymorphic arrangement?

Specifically the fact that SalesOrder must refer to multiple
addresses? Ignoring the polymorphic aspect I would normally just have:

--
belongs_to :delivery_address, :class_name => 'Address'
belongs_to :billing_address, :class_name => 'Address'
--

However this does tend to end up with a slightly messy address table
with mixed reference methods, and it sounds more correct for the
address to belong to 'something' rather than the other way around. Can
this be solved or is this the limit?

class Address < ActiveRecord::Base
  belongs_to :addressable, :polymorphic => true
end

class Customer < ActiveRecord::Base
  has_many :addresses, as => :addressable
end

class SalesOrder < ActiveRecord::Base
  has_one :delivery_address, as => :addressable
  has_one :billing_address, as => :addressable
end

Thanks, Andrew


--~--~---------~--~----~------------~-------~--~----~
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