title: jsonapi::Serializer Specify Foreign Key in Association belongs_to / has_many
body: <p>I have a database that I cannot modify as it is a read-only populated from a node I don't control.</p>
  <p>This causes the tables to have <code>foreign_keys</code> that are different from the Rails default way.
  You can see the current situation in the models below:</p>
  <pre class="lang-rb prettyprint-override"><code># app/models/epoch_stake.rb
  class EpochStake &lt; DbSyncRecord
      self.table_name = 'epoch_stake'
      belongs_to :stake_address, foreign_key: :addr_id
  end
  
  # app/models/stake_address.rb
  class StakeAddress &lt; DbSyncRecord
      self.table_name = &quot;stake_address&quot;
      has_many :epoch_stakes, foreign_key: :addr_id
  end
  </code></pre>
  <blockquote>
  <p><code>addr_id</code> rather than <code>stake_address_id</code></p>
  </blockquote>
  <p>Now I am creating a controller to fetch one of the model, using a serializer to show the associated model.</p>
  <pre class="lang-rb prettyprint-override"><code>class EpochStakeController &lt; ApplicationController
      def index
          epoch_stakes = EpochStake.all
          render json: EpochStakeSerializer.new(epoch_stakes)
      end
  end
  </code></pre>
  <p>It seems though that when I try to tell the <code>JSONAPI::Serializer</code> to be aware of the different <code>foreign_key</code>, that doesn't get taken into account:</p>
  <pre class="lang-rb prettyprint-override"><code># app/serializers/epoch_stake_serializers.rb
  class EpochStakeSerializer
    include JSONAPI::Serializer
    attributes :epoch_no, :amount
    belongs_to :stake_address, foreign_key: :addr_id
  end
  </code></pre>
  <p>Infact when I query the controller (<code>/epoch_stakes</code>) with the configuration above I receive the following error, as if the serializer is trying to look for the association with the Rails default <code>foreign_key</code> rather than the one I specified in the serializer:</p>
  <pre class="lang-sh prettyprint-override"><code>NoMethodError: undefined method `stake_address_id' for #&lt;EpochStake:0x00007fcf9f22ad50&gt;
  Did you mean?  stake_address
                 stake_address=
  from /Users/sergio/.rvm/gems/ruby-2.6.1/gems/activemodel-6.1.3/lib/active_model/attribute_methods.rb:469:in `method_missing'
  </code></pre>
  <p>How can I make the serializer aware of the different <code>foreign_key</code>?</p>