title: debug an api response from a rails server
body: <p>I'm a front end guy having to debug a rails app and am a bit confused as to where exactly i should be looking in the source code to find the source of an error</p>
  
  <p>Basically i have 3 tables</p>
  
  <ol>
  <li>A user table (user id , username , avatarUrl)</li>
  <li>A Stream table (stream id, stream name etc)</li>
  <li>A Follow table (userid, streamid)</li>
  </ol>
  
  <p>A user can only have 1 stream.</p>
  
  <p>I'm sending the below api request from the front end to get a list of users following a particular stream</p>
  
  <p><code>/users/{id}/following</code> - retrieves the following list</p>
  
  <p>I can see the controller acting for this as </p>
  
  <pre><code>  def following
      following = FollowEntry.where(user_id: @user.id)
      render json: following, scope: @user
    end
  </code></pre>
  
  <p>The api response i get is quite weird. Basically the json response looks like the below (assuming i'm user kunkka)</p>
  
  <pre><code>[
   {
    "id":1,
    "stream":{"id":1,"title":"Stream","slug":"bowie"},
    "user":{"id":2,"username":"kunkka"}
   },
   {
    "id":2,
    "stream":{"id":2,"title":"Stream","slug":"wilson"},
    "user":{"id":2,"username":"kunkka"}
   },
   {
    "id":3,
    "stream":{"id":3,"title":"Stream","slug":"doug"},
    "user":{"id":2,"username":"kunkka"}
   },
  ]
  </code></pre>
  
  <p>As you can see , all objects seem to have the same user attribute 'kunkka'(me) while in fact i would need the user object to belong/relate to their respective stream ids</p>
  
  <p>This is the <code>FollowEntry.rb</code> file</p>
  
  <pre><code>class FollowEntry &lt; ApplicationRecord
    belongs_to :user
    belongs_to :stream
  
    validates_uniqueness_of :user_id, :scope =&gt; :stream_id
  end
  </code></pre>
  
  <p>And the <code>FollowEntrySerializer</code> file</p>
  
  <pre><code>class FollowEntrySerializer &lt; ActiveModel::Serializer
    attributes :id
    has_many :stream
    has_one :user
  end
  </code></pre>
  
  <p>My FollowEntry schema</p>
  
  <pre><code>  create_table "follow_entries", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
      t.integer  "user_id",                       null: false
      t.integer  "stream_id",                     null: false
      t.index ["stream_id"], name: "index_follow_entries_on_stream_id", using: :btree
      t.index ["user_id"], name: "index_follow_entries_on_user_id", using: :btree
    end
  </code></pre>
  
  <p>Where is it going wrong? </p>
  
  <p><strong>UPDATE</strong> - i did a bit more debugging and this is the output in my console</p>
  
  <pre><code>  FollowEntry Load (0.1ms)  SELECT `follow_entries`.* FROM `follow_entries` WHERE `follow_entries`.`user_id` = 2
  [active_model_serializers]   Stream Load (1.4ms)  SELECT  `streams`.* FROM `streams` WHERE `streams`.`id` = 1 LIMIT 1
  [active_model_serializers]   User Load (1.6ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1
  [active_model_serializers]   Stream Load (17.9ms)  SELECT  `streams`.* FROM `streams` WHERE `streams`.`id` = 3 LIMIT 1
  [active_model_serializers]   CACHE (0.0ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1  [["id", 2], ["LIMIT", 1]]
  </code></pre>
  
  <p>The <code>User Load</code> should actually filter by the result user.id column recieved from the previous Stream Load (in this case - it should be 1 and not 2) - Where do i change this?</p>