Alain Ravet
2006-Mar-08 10:55 UTC
[Rails] combining STI + polymorphism + rich self HABTM : how to ?
Hi all, I need to model simple typed polymorphic relations: ''John'' [''works_for''] ''Bill'' ''John'' [''speaks_for''] ''Microsoft'' ''Microsoft'' [''hold_shares_of''] ''Apple'' I''m having a hard time combining : - S.T.I. : ''people'' and ''companies'' are different kind of ''entities'' that can relate to other ''entities'' - polymorphism self-ref HABTM (a person is related to another person OR to a company) - rich HABTM : relations are typed (''can_speak_for'', ''works_for'', ''works_with'', ''knows'', ..) I have already used those techniques separatedly, but combining them is another story!! What I have : *************** STI models: ------------- The main actors are People and Companies. They have a lot of common data and represent a common concept: Entity class Entity < ActiveRecord::Base class Person < Entity class Company < Entity table "relations" ------------------ # of_id :integer(11) = the left party: john, MSFT # of_type :string(20) # with_id :integer(11) = the right party.. # with_type :string(20) # relation_type_id :integer(11) = L.U.T: "works_for", "knows" relationship models ---------------- class Relation < AR::B class RelationType < AR::B What I don''t know: ***************** How to associate all those pieces? (belongs_to, has_many, :as => ..., :foreign_key, ...) I''m lost. Help. 911 Thanks in advance. Alain -- Posted via http://www.ruby-forum.com/.
Apparently Analagous Threads
- NameError when trying to combine Recipe 14 (rich HABTM) & Rec. 10 (self-ref HABTM):
- How do I combine :finder_sql and :conditions to perform a sub-search on a custom has_many relationship?
- Trouble combining :has_many, :finder_sql and :conditions to create a sub-search
- Problems with URL encoding
- Mocks? Really?