diff --git a/app/models/photo.rb b/app/models/photo.rb index 3e0254800..508a93615 100644 --- a/app/models/photo.rb +++ b/app/models/photo.rb @@ -11,7 +11,7 @@ class Photo < ApplicationRecord # This doesn't work, ActiveRecord tries to use the polymoriphinc photographable # relationship instead. - # has_many :crops, through: :photo_associations + # has_many :crops, through: :photo_associations, counter_cache: true def crops Crop.distinct.joins(:photo_associations).where(photo_associations: { photo: self }) end diff --git a/app/models/photo_association.rb b/app/models/photo_association.rb index e253a3a50..81477d78f 100644 --- a/app/models/photo_association.rb +++ b/app/models/photo_association.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class PhotoAssociation < ApplicationRecord - belongs_to :photo, touch: true + belongs_to :photo, touch: true, inverse_of: :photo_associations belongs_to :crop, optional: true, touch: true # , counter_cache: true belongs_to :photographable, polymorphic: true, touch: true