mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-03-29 12:12:57 -04:00
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user