<p>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!</p>

[{'answer_id': 62677, 'author': 'Clinton Dreisbach', 'author_id': 6262, 'author_profile': 'https://Stackoverflow.com/users/6262', 'pm_score': 3, 'selected': False, 'text': "<p>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.</p>\n"}, {'answer_id': 62743, 'author': 'Ben', 'author_id': 6998, 'author_profile': 'https://Stackoverflow.com/users/6998', 'pm_score': 3, 'selected': False, 'text': '<p>You should definitely use one model per table in order to take advantage of all the ActiveRecord magic.  </p>\n\n<p>But you could also group your models together into namespaces using modules and sub-directories, in order to avoid having to manage 70 files in your models directory.</p>\n\n<p>For example, you could have:</p>\n\n<pre><code>app/models/admin/user.rb\napp/models/admin/group.rb\n</code></pre>\n\n<p>for models Admin::User and Admin::Group, and</p>\n\n<pre><code>app/models/publishing/article.rb\napp/models/publishing/comment.rb\n</code></pre>\n\n<p>for Publishing::Article and Publishing::Comment</p>\n\n<p>And so forth...</p>\n'}, {'answer_id': 63689, 'author': 'James A. Rosen', 'author_id': 1190, 'author_profile': 'https://Stackoverflow.com/users/1190', 'pm_score': 1, 'selected': False, 'text': "<p>There may be a small number of cases where you can use the Rails standard single-table-inheritance model.  Perhaps all of the classes in one particular functional grouping have the same fields (or nearly all the same).  In that case, take advantage of the DRYness STI offers.  When it doesn't make sense, though, use class-per-table.</p>\n\n<p>In the class-per-table version, you can't easily pull common functionality into a base class.  Instead, pull it into a module.  A hierarchy like the following might prove useful:</p>\n\n<pre><code>app/models/admin/base.rb - module Admin::Base, included by all other Admin::xxx\napp/models/admin/user.rb - class Admin::User, includes Admin::Base\napp/models/admin/group.rb - class Admin::Group, includes Admin::Base\n</code></pre>\n"}, {'answer_id': 65340, 'author': 'srboisvert', 'author_id': 6805, 'author_profile': 'https://Stackoverflow.com/users/6805', 'pm_score': 2, 'selected': False, 'text': "<p>Without knowing more details about the nature of the seventy tables and their conceptual relations it isn't really possible to give a good answer. Are these legacy tables or have you designed this from scratch?</p>\n\n<p>Are the tables related by some kind of inheritance pattern or could they be?  Rails can do a limited form of inheritance. Look up Single Table Inheritance (STI).</p>\n\n<p>Personally, I would put a lot of effort into avoiding working with seventy tables simply because that is an awful lot of work - seventy Models &amp; Controllers and their 4+ views, helpers, layouts, and tests not to mention the memory load issue of keeping the design in ind.  Unless of course I was getting paid by the hour and well enough to compensate for the repetition.</p>\n"}, {'answer_id': 68536, 'author': 'Dave Smylie', 'author_id': 1505600, 'author_profile': 'https://Stackoverflow.com/users/1505600', 'pm_score': 1, 'selected': False, 'text': "<p>It's already mentioned, it's hard to give decent advice without knowing your database schema etc, however, I would lean towards creating the 70+ models, (one for each of your tables.)</p>\n\n<p>You may be able to get away with ditching some model, but for the cost (negliable) you may as well have them there. </p>\n\n<p>You don't need to create a controller + views for each model (as answerd by srboisvert). You only need a controller for each resource (which I would expect to be a lot less than 70 - probably only 10 or 15 or so judging by your description).</p>\n"}, {'answer_id': 68571, 'author': 'ctcherry', 'author_id': 10322, 'author_profile': 'https://Stackoverflow.com/users/10322', 'pm_score': 2, 'selected': False, 'text': '<p>Before jumping in a making 70 models, please consider this question to help you decide:</p>\n\n<p>Would each of your tables be considered an "object" for example a "cars" table or are some of the tables holding only relationship information, all foreign key columns for example?</p>\n\n<p>In Rails only the "object" tables become models! (With some exception for specific types of associations) So it is very likely that if you have only 5 groups of functionality, you might not have 70 models. Also, if the groups of functionality you mentioned are vastly different, they may even be best suited in their own app.</p>\n'}, {'answer_id': 99671, 'author': 'Dan Harper', 'author_id': 14530, 'author_profile': 'https://Stackoverflow.com/users/14530', 'pm_score': 4, 'selected': True, 'text': "<p>I cover this in one of my large apps by just making sure that the tables/models are conceptually grouped by name (with almost 1:1 table-model relationship).  Example:</p>\n\n<pre><code>events\nevent_types\nevent_groups\nevent_attendees\netc...\n</code></pre>\n\n<p>That way when I'm using TextMate or whatever, the model files are nicely grouped together by the alpha sort.  I have 80 models in this app, and it works well enough to keep things organised.</p>\n"}]
['https://Stackoverflow.com/questions/62529', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6941/']