i have a problem which is i believe basic for most of the RoR developers. In fact, it's more about "understanding" than really programming it (i have already been programming a few modules to be able to extend ActiveRecord::Base to allow easy generation of Ext-JS related things without any problem).
Let's take a simple example, i'll talk in an ORM oriented language rather than a database / model language.
- ThirdParty is a basic entity, having a common member named 'label'.
- A ThirdParty instance can be a Customer, a Supplier, both, or none of them (So Customer / Supplier are like concrete interfaces rather than inherited classes).
- Both Customer and Supplier have specialized members, which are for most of them unique to each respective class (Customer / Supplier don't share much data except the label field they are bound to via ThirdParty).
i have tried to do various things:
- ThirdParty < ActiveRecord::Base
- Customer < ThirdParty
- Supplier < ThirdParty
[EDIT] Missed my explanation here. i meant: one single instance of ThirdParty could be a customer, a supplier, BOTH, OR NONE. As the first commenter pointed out, my example might not be the best... You can replace "ThirdParty" by "Character", and "Customer" / "Supplier" by "Archer" / "SwordsMan". A character can either be one, two, both, or none, but would provide the information on any instance of Character. The getters on Archer / SwordsMan shall return instances of Character "implementing" the interface contract, rather than just returning an instance of themself with a "getter" on the character object. [/EDIT]
Also i have tried:
- ThirdParty < ActiveRecord::Base (has_one Customer; has_one Supplier)
- Customer < ActiveRecord::Base (belongs_to ThirdParty)
- Supplier < ActiveRecord::Base (belongs_to ThirdParty)
But it seems a bit "ugly" to me, because i have to do Customer.find(something).third_party.label to access data "inherited" by my "interfaces".
Also, i could include a customer_id and a supplier_id field on my ThirdParty model, but it doesn't seem right neither, because one ThirdParty can be both, or none of them...
And of course, i'd like to be able to find a solution which isn't obstructive / too much of a hack, to allow me for instance to then do some polymorphic association for another model (Such as an addressable, or commentable, contactable, etc...)
i also have been reading a lot on the subject like on such blog: http://mediumexposure.com/multiple-table-inheritance-active-record/ ... But i'am lost in the right way to do it (On most of the documentation i have found on the subject isn't clear if it's for Rails 1, 2, 3... What's recently been implemented on the matter, etc).
Can someone provide me with various "up-to-date" websites or to an example fitting the example i have given?
By advance, i thank you all for having red my question, and to edventually explain me the different techniques used regarding this particular subject.
P.S.: If you need me to explain more what i'm looking for, i can try... But keep in mind that my english is a bit "limited" on this domain, since i'm relatively new to RoR.