Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extends ignores eager loaded data #380

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

Extends ignores eager loaded data #380

simonc opened this issue Dec 21, 2012 · 1 comment

Comments

@simonc
Copy link

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
@nesquena
Copy link
Owner

nesquena commented Dec 6, 2013

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

@nesquena nesquena closed this as completed Dec 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants