[Rails] Re: How to model a polymorphic relationship?

2008-09-18 Thread Reiner Pittinger
I came to the solution using the has_many_polymorphs plugins: The correct modelling is: class Relationship < ActiveRecord::Base belongs_to :relationship_owner, :polymorphic => true belongs_to :relationship_partner, :polymorphic => true acts_as_double_polymorphic_join( :relationsh

[Rails] Re: How to model a polymorphic relationship?

2008-09-10 Thread Ar Chron
Search for "Rails double polymorphic" in Google... http://wiki.rubyonrails.org/rails/pages/ManytoManyPolymorphicAssociations http://blog.evanweaver.com/files/doc/fauna/has_many_polymorphs/files/README.html or just assume that everyone else will do the googling for you... -- Posted via http://ww

[Rails] Re: How to model a polymorphic relationship?

2008-09-10 Thread Reiner Pittinger
Dear Ilan, although I just supplied just three basic models, my application already contains more than 15 different models that should be linked to each other. Some more examples: - I need a relationship between two documents ("Like: Document B is an attachment to Document A). - I need a rel

[Rails] Re: How to model a polymorphic relationship?

2008-09-10 Thread Ilan Berci
Reiner, My suggestion then is to come up with your classes first and then make a design. A very common pitfall is to design for something that "may" happen and then later face over engineered code.. In the late nineties, we called this the YAGNI principle which stood for "You Aint Going to N

[Rails] Re: How to model a polymorphic relationship?

2008-09-09 Thread Reiner Pittinger
Hi Ilan, thank you for your answer: Ilan Berci wrote: > class Person < ActiveRecord::Base > has_many :documents > has_many :realties > end > > class Document < ActiveRecord::Base > belongs_to :owner, class_name => "Person" > belongs_to :realty > end > > class Realty < ActiveRecord::Base > bel

[Rails] Re: How to model a polymorphic relationship?

2008-09-09 Thread Ilan Berci
Reiner, I don't believe you have the need for polymorphic associations in the above example as you have a seperate association "type" already specced out for each relation class Person < ActiveRecord::Base has_many :documents has_many :realties end class Document < ActiveRecord::Base belongs_