From cae9fffea6021ba1c664c273a04116a9bbf00c0b Mon Sep 17 00:00:00 2001 From: Brenda Wallace Date: Sat, 21 Dec 2019 09:36:52 +1300 Subject: [PATCH] Index crop as well on photo changes --- app/models/garden.rb | 3 +++ app/models/photo_association.rb | 10 ++++++++-- app/models/post.rb | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/garden.rb b/app/models/garden.rb index 95c619dbe..0003b2276 100644 --- a/app/models/garden.rb +++ b/app/models/garden.rb @@ -77,6 +77,9 @@ class Garden < ApplicationRecord end end + def reindex + end + protected def strip_blanks diff --git a/app/models/photo_association.rb b/app/models/photo_association.rb index b09d94ca5..40004e4b7 100644 --- a/app/models/photo_association.rb +++ b/app/models/photo_association.rb @@ -10,8 +10,8 @@ class PhotoAssociation < ApplicationRecord ## ## Triggers before_save :set_crop - after_create { |record| record.photographable.reindex } - after_destroy { |record| record.photographable.reindex } + after_create :reindex + after_destroy :reindex def item photographable @@ -31,6 +31,12 @@ class PhotoAssociation < ApplicationRecord private + def reindex + photographable.reindex + crop&.reindex + true + end + def photo_and_item_have_same_owner return unless photographable_type != 'Crop' diff --git a/app/models/post.rb b/app/models/post.rb index 659291584..6eff19a35 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -57,6 +57,9 @@ class Post < ApplicationRecord subject end + def reindex + end + private def update_crop_posts_association