Extends ignores eager loaded data #380

Closed
simonc opened this Issue Dec 21, 2012 · 1 comment

Comments

Projects
None yet
2 participants

simonc commented Dec 21, 2012

Say I have the following models

class Region < ActiveRecord::Base
  has_many :departments
end

class Department < ActiveRecord::Base
  belongs_to :region
end

In my controller I use includes because I need the department ids in my template.

class RegionsController < ApplicationController
  def index
    @regions = Regions.includes(:departments).all
  end
end

When I don't use extends in my template it works fine with only 2 queries.

# app/views/regions/index.json.rabl
collection @regions
attributes :id, :name, :department_ids

But, when I use extends the eager loaded data are ignored and N+1 queries come around.

# app/views/regions/index.json.rabl
collection @regions
extends 'regions/show'

# app/views/regions/show.json.rabl
object @region
attributes :id, :name, :department_ids
Owner

nesquena commented Dec 6, 2013

I think this has been fixed. If not, please re-open

@nesquena nesquena closed this Dec 6, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment