Hi! I have the next abstract composition: Organization ConsultingFirm IS A Organization Client IS A Organization User ConsultingFirmUser IS A User ClientUser IS A User ConsultingFirmUser BELONGS TO ConsultingFirm ClientUser BELONGS TO Client ConsultingFirm HAS MANY ConsultingFirmUsers Client HAS MANY ClientUsers I don''t know how is the best way of implementing the "IS A" relationship in Rails. What would you use? Inheritance or Polymorphism? Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald
2009-Apr-01 21:45 UTC
Re: Inheritance vs Polymorphism: Design Question for "IS A"
On Wed, Apr 1, 2009 at 2:33 AM, Juan Kinunt <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Organization > ConsultingFirm IS A Organization > Client IS A Organization > > User > ConsultingFirmUser IS A User > ClientUser IS A User > > ConsultingFirmUser BELONGS TO ConsultingFirm > ClientUser BELONGS TO Client > > ConsultingFirm HAS MANY ConsultingFirmUsers > Client HAS MANY ClientUsers > > I don''t know how is the best way of implementing the "IS A" relationship > in Rails. What would you use? Inheritance or Polymorphism?I would use a roles table and join model between users and roles. -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Robert Walker
2009-Apr-03 01:29 UTC
Re: Inheritance vs Polymorphism: Design Question for "IS A"
Juan Kinunt wrote:> I don''t know how is the best way of implementing the "IS A" relationship > in Rails. What would you use? Inheritance or Polymorphism?There are two primary solutions provided by rails for this: 1: Single Table Inheritance (STI) 2: Polymorphic relationships. The primary determining factor is how similar are the "subclasses" to the abstract class. By this I mean do the subclasses add just a few additional attributes to the superclass or do they add a lot. In the former case STI may fit the bill very well and in the latter you''re probably better off using a polymorphic relationship. Google the two key words (STI and "Polymorphic Relationship") and you should find lots of information to help you decide what''s best in your case. That is if either one fits, which I think one of them will. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---