Rails включает в себя has_many, давая возможность избежать загрузки eger n + 1 с помощью пули - PullRequest
0 голосов
/ 25 апреля 2020

Мои модели имеют вид:

class ThreeDModel < ApplicationRecord
  has_many :three_d_model_animations
  has_many :animations, through: :three_d_model_animations
  has_many :three_d_model_images, dependent: :destroy
  has_many :three_d_garments
  has_one :model_efm
  has_one :model_edm
end

2-й:

    class ThreeDModelAnimation < ApplicationRecord
      belongs_to :animation
      belongs_to :three_d_model
      validates_presence_of :animation_file
      #validates_presence_of :motion
      mount_uploader :animation_file, ThreeDModelAnimationUploader
      enum animation_motions: {
          'Run': 'run',
          'Turn Aroun (100 Frames)': 'turn_around_100_frames',
          'Turn Around (300 Frames)': 'turn_around_300_frames',
          'Walk (58 Frames)': 'walk_58_frames',
          'Walk (92 Frames)': 'walk_92_frames'
      }
    end

3-й:

class Animation < ApplicationRecord
  has_many :three_d_model_animations
  has_many :three_d_models, through: :three_d_model_animations
  mount_uploader :video, AnimationVideoUploader
  validates_presence_of :video

  validates :name, :frames, :loop_start, :loop_end, presence: true
end

Теперь мой запрос:

    @model = ThreeDModel.where(id: params[:id]).includes(:model_efm, :model_edm, :three_d_model_images, :three_d_model_animations, :animations).last

, который выдает следующее слово от пули:

AVOID eager loading detected
  ThreeDModel => [:three_d_model_animations, :animations]

есть лучший способ избежать n + 1. Заранее спасибо

...