title: What is the foreign key in a one-to-many self join in sequelize?
body: <p>I have an <code>Institution</code> model, where an Institution can belong to a <code>Parent Institution</code> and I'm setting this up as a self-join on the <code>institutions</code> table. </p>
  
  <p>I'm using <code>sequelize</code> to set this up on postgres and the docs talk about how to set a self-join for a many-to-many association, but my model uses a one-to-many self-join (i.e. a parent Institution can have many children, but a child institution can only belong to 1 parent).</p>
  
  <p>This is my model:</p>
  
  <pre><code>module.exports = (sequelize, DataTypes) =&gt; {
    const Institution = sequelize.define(
      'Institution',
      {
        /* ... */
  
        parentId: DataTypes.INTEGER,
  
        /* ... */
      },
      {}
    )
    Institution.associate = function (models) {
      // associations can be defined here
      Institution.belongsTo(Institution, {
        foreignKey: 'institutionId',
        as: 'parent',
      })
    }
    return Institution
  }
  </code></pre>
  
  <p>What I'm not sure about is what to put as the <code>foreignKey</code> in the association above - should it be <code>institutionId</code> as I've put it now (i.e. with the <code>as: parent</code> parameter) or should it be <code>parentId</code>?</p>
  
  <p>Thanks in advance!</p>