Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best Practice for Model Design in Ruby on Rails

The RoR tutorials posit one model per table for the ORM to work. My DB schema has some 70 tables divided conceptually into 5 groups of functionality (eg, any given table lives in one and only one functional group, and relations between tables of different groups are minimised.) So: should I design a model per conceptual group, or should I simply have 70 Rails models and leave the grouping 'conceptual'? Thanks!

like image 736
NickR Avatar asked Sep 15 '08 12:09

NickR


People also ask

What is the best practice for Ruby on Rails?

Ruby on Rails Best Practice: Keep Your Code DRY Ruby on Rails' object-oriented principles are built to help you avoid duplicating code throughout your web application. Whenever possible, a great Ruby on Rails tip is to re-use as much code as possible instead of repeating similar code in many places.

Is Shopify written in Ruby on Rails?

c) Ruby on Rails is the language on which Shopify itself is built, so creating a custom app with RoR as its foundation will ensure it talks seamlessly to your Shopify store.


Video Answer


1 Answers

Most likely, you should have 70 models. You could namespace the models to have 5 namespaces, one for each group, but that can be more trouble than it's worth. More likely, you have some common functionality throughout each group. In that case, I'd make a module for each group containing its behavior, and include that in each relevant model. Even if there's no shared functionality, doing this can let you quickly query a model for its conceptual group.

like image 148
Clinton Dreisbach Avatar answered Oct 12 '22 21:10

Clinton Dreisbach