Vikrant Rathore wrote:
class Vendor < Company
class QuoteSheet < ActiveRecord::Base
belongs_to :customer
has_many :vendors
has_one :Agent
end
Without knowing all the details I can’t be sure, but my first impression
is that vendor, customer and agent are roles rather than types. Could
the same Company be a vendor with respect to one QuoteSheet, and a
customer with respect to another? If you use subclasses in the way you
suggest, this wouldn’t be possible.
I think your associations need a little attention:
belongs_to :customer looks fine - so a customer would be able to have
many QuoteSheets
has_many :vendors looks wrong - that would mean a vendor would belong to
one QuoteSheet - I think it should be has_and_belongs_to_many
has_one :agent (not :Agent) looks wrong - that would mean an agent would
belong to one QuoteSheet - it should be belongs_to (which really means
refers_to)
QuoteSheet might look something like:
class QuoteSheet < ActiveRecord::Base
belongs_to :customer,
:class_name => “Company”,
:foreign_key => “customer_id”
belongs_to :agent,
:class_name => “Company”,
:foreign_key => “agent_id”
has_and_belongs_to_many :vendors,
:class_name => “Company”,
:join_table => “quote_sheets_vendors”
end
(absolutely untested!)
You would have to think about how to name the other ends of the
associations, i.e. the collection of QuoteSheets received as a customer,
the collection of QuoteSheets issued as an agent, and the collection of
QuoteSheets quoted on as a vendor.
Is there a bit of model missing here - the actual quote from each
vendor?
HTH
Justin