Missing Eager Load (ARCH6051)
هذا المحتوى غير متوفر بلغتك بعد.
Key ruby.orm.missing-eager-load · Severity warning · Category orm
A query that iterates over related data without declaring eager loading is the root cause of N+1. In ActiveRecord the relation must be preloaded with includes/preload/eager_load.
Incorrect
Section titled “Incorrect”def comment_authors Comment.recent.map { |c| c.user.email } # user not eager-loadedendCorrect
Section titled “Correct”def comment_authors Comment.recent.includes(:user).map { |c| c.user.email }endDeclare the relations accessed inside the loop with includes so they load in a single query.