Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In short - no there no nice clean STI API for what you are trying to accomplish as of right now.</p> <p>I actually looked into that a about a year ago and came to a conclusion that it is not a good idea for several reasons:</p> <ol> <li>If you want to utilize PostgreSQL specific features - you are basically marrying yourself to that DB. Don't get me wrong PostgreSQL is a great DB and I've used it on a number of occasions, but you are going to be stuck with that DB and app design.</li> <li>Most likely if you start using DB specific features you'll either end up implementing them manually ( running some kind of commands on the DB or using GUI) or writing some kind of script that you will have to invoke whenever you are running db:migrate ( you will have to do it if you want to do proper testing). After awhile it becomes cumbersome and annoying.</li> <li>If you find that you are more and more annoyed with, to quote you <strong>"painfully wide tables and "type" columns"</strong> then: <ul> <li>Your table design needs to be rethought and redone</li> <li>Your models may not be a good candidates for STI</li> <li>You just have to live with it. </li> </ul></li> </ol> <p>Most IT problems really come down to this: <strong>Effort vs Benefit.</strong> </p> <p>In your case you should ask yourself this question: </p> <ul> <li>How much time do you want to spend on implementing a better STI structure if it will only speed up your raw SQL query by a few seconds? Maybe it's better to write a more explicative SQL query? Most applications don't grow to the size where it really becomes an issue. But it maybe different in your case.</li> </ul> <p><strong>P.S.:</strong></p> <p>Also a quick tip on structuring STI in your app: If you find that you have a lot of models that use STI like a ProductCategory, CommentCategory, PhoneCategory, ClientCategory that all inherit from Cateogory - I tend to organize them in folders inside model directory. Then in <strong>application.rb</strong> just add a line: <code>config.autoload_paths += Dir[Rails.root.join('app', 'models', '{**/**}')]</code></p>
    singulars
    1. This table or related slice is empty.
    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.
    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