0

My Models are like:

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

2nd:

    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

3rd:

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

Now my query is:

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

which gives the following message by the bullet gem:

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

is there a better way so that n+1 could be avoided. Thanks in advance

vidur punj
  • 5,019
  • 4
  • 46
  • 65
  • Will it resolve the n+1issue ? – vidur punj Apr 26 '20 at 05:32
  • can you please share the answer, about where and how to apply it? – vidur punj Apr 26 '20 at 09:01
  • Would you mind also posting the SQL the command generates for more clarity? Alternatively, I'd recommend reverting to a state where Bullet and the query no longer has the N+1 and incrementally add the changes back until it does get introduced. That might provide you some pointers on where to focus more specifically. Hope that helps. – Gustavo Matias Feb 26 '21 at 04:30

0 Answers0