Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The default Rails inheritance model is Single Table Inheritance and is the simplest, cleanest, most generic, and most database-agnostic thing to do.</p> <p>It is accomplished simply by having Answer and Question inherit from Post. Then you create a posts table that has all the fields you want in Post, Answer, and Question. </p> <p>Single Table Inheritance isn't the most space-efficient technique because all rows in the posts table will have <em>all</em> the fields of Post, Answer, and Question. But it is conventional and if you run into space issues down the road you will be in a good position to migrate to a more scalable data model (like Multiple Table Inheritance). And Single Table Inheritance is efficient in the sense that it only requires a single query to find a post by ID, where in other data models there may be an extra query to find what table (post, question, answer) the post is in.</p> <p>As for connecting Comments and Posts, you can use a <code>belongs_to</code> relation in the Comment model that points to Post and a <code>has_many</code> relation in the Post model that points to Comment. (You will need to add a post_id integer field to the comments table to get this to work).</p> <p>cf. <a href="http://guides.rubyonrails.org/association_basics.html" rel="nofollow">http://guides.rubyonrails.org/association_basics.html</a></p> <p>You will also want to add an index for comments on post_id for quickly querying all the comments for a post: <a href="http://guides.rubyonrails.org/migrations.html" rel="nofollow">http://guides.rubyonrails.org/migrations.html</a> .</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. 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