Hello, I have a design question concerning my app with Rails. I have two types of users let''s call them Type1 and Type2. They both have very similar attributes but different associations and functionality. So for every type of user I will need different "has_many, has_one,...etc" Is it better to create one model and have another column called "type" knowing that whenever the model is loaded the associations for bother types will be loaded or is it better to create two separate models and have every model gets its own associations? I care about performance but if it''s not significant then it doesn''t matter as much. I also care about complexity in case the application expands in future. Thanks, Tam -- 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 -~----------~----~----~----~------~----~------~--~---
Instead of using inheritance, you should use a role based solution. One of the cleanest I''ve used is Acl9, http://github.com/be9/acl9/tree/master This will also fit your needs for future complexity since roles are abstracted out of the model and into a separate table. So if you ever need to add more roles, it wouldn''t change your database design at all. On Apr 11, 2:27 am, Tam Kbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, > > I have a design question concerning my app with Rails. I have two types > of users let''s call them Type1 and Type2. They both have very similar > attributes but different associations and functionality. > > So for every type of user I will need different "has_many, > has_one,...etc" > > Is it better to create one model and have another column called "type" > knowing that whenever the model is loaded the associations for bother > types will be loaded or is it better to create two separate models and > have every model gets its own associations? > > I care about performance but if it''s not significant then it doesn''t > matter as much. I also care about complexity in case the application > expands in future. > > Thanks, > > Tam > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks Jaryl, But would using role-base solution lower the performance of my app by having to load the associations for all roles every time the model is loaded? Thanks, Tam -- 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 -~----------~----~----~----~------~----~------~--~---
There will definitely be a performance hit, but I don''t know if it will make much of a difference in your situation. I can''t provide any hard evidence, but there are many ways you can go about improving performance for loading associations. I''m sure you are aware of eager loading; you can start with that. On Apr 11, 2:42 am, Tam Kbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Thanks Jaryl, > > But would using role-base solution lower the performance of my app by > having to load the associations for all roles every time the model is > loaded? > > Thanks, > > Tam > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tam Kbe wrote:> Thanks Jaryl, > > But would using role-base solution lower the performance of my app by > having to load the associations for all roles every time the model is > loaded?Google "premature optimizations". There''s generally no way to guess which part of your code will be slow, so if you keep it clean and easy to change you can then fix the parts that actually slow it down. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
http://stonean.com/projects/lockdown does roles without loading from the DB on every access. I like how the specification of all permissions and groups are in one place. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Role-based auth is one possibility, but single-table inheritance is another. It''s very dependent on how your app handles permissions; if a user can have a mixture of different permissons, role-based is better. On the other hand, if your app has clearly delimited user categories (ie Employee vs. Client, etc) inheritance may be preferable. You can then specify the common associations in the base User class, while putting any extra info in the subclasses. --Matt Jones On Apr 10, 2:27 pm, Tam Kbe <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, > > I have a design question concerning my app with Rails. I have two types > of users let''s call them Type1 and Type2. They both have very similar > attributes but different associations and functionality. > > So for every type of user I will need different "has_many, > has_one,...etc" > > Is it better to create one model and have another column called "type" > knowing that whenever the model is loaded the associations for bother > types will be loaded or is it better to create two separate models and > have every model gets its own associations? > > I care about performance but if it''s not significant then it doesn''t > matter as much. I also care about complexity in case the application > expands in future. > > Thanks, > > Tam > -- > Posted viahttp://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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---