Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If the differences are just in the behavior of the class, then I assume it shouldn't be a problem, and this is a good candidate for STI. (Mind you, I've never tried this with so many subclasses.)</p> <p>But, if your 200 STI classes each have some unique attributes, you would need a lot of extra database columns in the master table which would be NULL, 99.5% of the time. This could be very inefficient.</p> <p>To create something like "multiple table inheritance", what I've done before with success was to use a little metaprogramming to associate other tables for the details unique to each class:</p> <pre><code>class SpecificGraph &lt; Graph include SpecificGraphDetail::MTI end class SpecificGraphDetail &lt; ActiveRecord::Base module MTI def self.included(base) base.class_eval do has_one :specific_graph_detail, :foreign_key =&gt; 'graph_id', :dependent =&gt; :destroy delegate :extra_column, :extra_column=, :to =&gt; :specific_graph_detail end end end end </code></pre> <p>The delegation means you can access the associated detail fields as if they were directly on the model instead of going through the <code>specific_graph_detail</code> association, and for all intents and purposes it "looks" like these are just extra columns.</p> <p>You have to trade off the situations where you need to join these extra detail tables against just having the extra columns in the master table. That will decide whether to use STI or a solution using associated tables, such as my solution above.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload