Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your join table has to be called <code>incidents_users</code> because the Rails' convention when using a <code>has_and_belongs_to_many</code> association is that the table name is derived from the lexical order of the class names of the models that comprise the association.</p> <p>From the <a href="http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#M001836" rel="noreferrer">documentation</a>:</p> <blockquote> <p>So a join between Developer and Project will give the default join table name of "developers_projects" because "D" outranks "P". Note that this precedence is calculated using the &lt; operator for String. This means that if the strings are of different lengths, and the strings are equal when compared up to the shortest length, then the longer string is considered of higher lexical precedence than the shorter one. For example, one would expect the tables "paper_boxes" and "papers" to generate a join table name of "papers_paper_boxes" because of the length of the name "paper_boxes", but it in fact generates a join table name of "paper_boxes_papers".</p> </blockquote> <p>Note that the table name can be overridden using the <code>:join_table</code> option when specifying the association, so:</p> <pre><code>class Incident &lt; ActiveRecord::Base has_and_belongs_to_many :users, :join_table =&gt; 'users_incidents' end class User &lt; ActiveRecord::Base has_and_belongs_to_many :incidents, :join_table =&gt; 'users_incidents' end </code></pre> <p>&mdash;It's generally best just to go with the Rails' conventions though, unless you've a particular reason that's preventing you.</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