Ali
2010-May-24 02:17 UTC
derived model associates with a model that base associates with in a different way
Hello, So I have an Attribute model with lists the attributes of an object. The attributes can be of different types so I have derived classes as well, in this case I have a derived SubjectiveAttribute. The problem I''m having revolves around my User model. A user is allowed to give each attribute a weighting (which tells the system how important an attribute is to a user). So, there''s a Weight model and then Attribute has the associations has_many :weights and has_many :users, :through => :weights. The problem is that SubjectiveAttribute is related to the users in a different way, subjective attributes can be rated as well as weighted. So SubjectiveAttribute has the association has_many :ratings and has_many :users, :through => :ratings. def Attribute belongs_to :attributable, :polymorphic => true has_many :weights has_many :users, :through => :weights def SubjectiveAttribute < Attribtue has_one :attribute, :as => :attributable has_many :ratings has_many :users, :through => :ratings Is this ok or are there problems which could occur that I''m no seeing? Are there going to be clashes or confusion when I do something like sub_attribute.users or attribute.users? Thanks in advance. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.