database - Rails ORM query results -


why doesn't ruby on rails framework provide method understand if operation i'm doing cause query or not?

take user has many posts

in view do:

<% @user.posts.each |p| %>   <%= p.title %> <% end %> 

i have no way see if in controller did

@user = user.find(params[:id]).includes(:posts) 

that eager loading, , causes 1 query, left join, or if did:

@user = user.find(params[:id]) 

that causes n+1 queries

if application simple, there wouldn't problem, let's take larger application. maybe query method not in controller, in model. , maybe it's not in model, in concern (an external module, included model).

in other words have impression of losing control of framework doing database.

did find solutions problem?

you can add bullet gem in application prompt n+1 queries

add gem in application

gem "bullet", :group => "development" 

add below settings in configuration file config/environments/development.rb

config.after_initialize   bullet.enable = true   bullet.alert = true   bullet.bullet_logger = true end 

after should able monitor n+1 queries

more reference can checked in below link

https://github.com/flyerhzm/bullet


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -