Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Inconsistent suggestions with nested association calls #55

Closed
MartinKoerner opened this Issue · 6 comments

6 participants

@MartinKoerner

Using Rails 2.3.5 with Bullet 2.1.0, I have a model like this

MainModel < ActiveRecord::Base
  belongs_to :sub_model

  named_scope :my_finder, lambda {
     {:include => :sub_model, :conditions => ["...."] }
  }
end

SubModel < ActiveRecord::Base
   belongs_to :some_data
end

SomeData < ActiveRecord::Base
end

And my list is something like

results = MainModel.my_finder
results.each do |result|
  result.sub_model.some_data
end

Bullet now says

 N+1 Query detected
    SubModel => [:some_data]
    Add to your finder: :include => [:some_data]

First and second line are correct. But in the third line, Bullet should suggest :include => {:sub_model => :some_data}

If I add the ladder one, the N+1 Queries are gone. But Bullet complains

Unused Eager Loading detected
  SubModel => [:some_data]
  Remove from your finder: :include => [:some_data]
@shanetrotter

FWIW, I have the same issues, and I'm not using any lambdas or anything. It complains about N+1, then I add includes, and it complains about unused eager loading. And this is on a simple association (has_many).

@csgavino

+1 I keep getting the same issue. It's either N+1 then after adding the nested model includes I get an eager loading prompt.

@tute

+1

@Dagnan

Same.

@flyerhzm
Owner

I'm afraid I won't support rails 2.3 or less any more. I have tried with rails 3.2.13 and bullet 4.5.0, it seems working fine.

Feel free to reopen it and please give me more info how to reproduce it.

@flyerhzm flyerhzm closed this
@Dagnan

I didnt see this probem was related to Rails 2. I'm using the last version of Rails and had this too, I'll reopen a new ticket if I can reproduce this in a new app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.