Rails 5.
New app, all default.
Bullet gem tell me this:
user: root
/children/2
N+1 Query detected
Child => [:parent]
Add to your finder: :includes => [:parent]
N+1 Query method call stack
app/controllers/children_controller.rb:14:in `show'
app/controllers/children_controller.rb:14:in `show'
I have these models:
class Parent < ApplicationRecord
has_many :children
end
class Child < ApplicationRecord
belongs_to :parent
end
I have this controller in children_controller.rb with:
...
def show
@parent = @child.parent
end
...
In my views views/children/show.html.erb I have this:
...
<%= @parent.name %>
...
If I invert this and in view I put:
<%= @child.parent.name %>
and in controller:
...
def show
#nothing more
end
...
I have the same error from Bullet but in html.
How to fix this? Is really a N+1 problem or Bullet is wrong?
The project is really really new. First models.