Inconsistent suggestions with nested association calls #55

Closed
MartinKoerner opened this Issue Feb 9, 2012 · 6 comments

Comments

Projects
None yet
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

This comment has been minimized.

Show comment Hide comment
@shanetrotter

shanetrotter Mar 8, 2012

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).

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

This comment has been minimized.

Show comment Hide comment
@csgavino

csgavino Jul 22, 2012

+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.

+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

This comment has been minimized.

Show comment Hide comment
@tute

tute Mar 18, 2013

+1

tute commented Mar 18, 2013

+1

@Dagnan

This comment has been minimized.

Show comment Hide comment
@Dagnan

Dagnan Mar 20, 2013

Same.

Dagnan commented Mar 20, 2013

Same.

@flyerhzm

This comment has been minimized.

Show comment Hide comment
@flyerhzm

flyerhzm Mar 28, 2013

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.

Owner

flyerhzm commented Mar 28, 2013

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 Mar 28, 2013

@Dagnan

This comment has been minimized.

Show comment Hide comment
@Dagnan

Dagnan Mar 28, 2013

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.

Dagnan commented Mar 28, 2013

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