This commit is contained in:
Mackenzie Morgan
2016-11-30 09:47:48 -05:00
parent a5fcfb6277
commit aa7ca71e5d
3 changed files with 5 additions and 8 deletions

View File

@@ -8,11 +8,9 @@ module PhotoCapable
end
def remove_from_list
photolist = self.photos.to_a # save a temp copy of the photo list
self.photos.clear # clear relationship b/w object and photo
photolist = photos.to_a # save a temp copy of the photo list
photos.clear # clear relationship b/w object and photo
photolist.each do |photo|
photo.destroy_if_unused
end
photolist.each(&:destroy_if_unused)
end
end

View File

@@ -8,7 +8,6 @@ class Harvest < ActiveRecord::Base
belongs_to :owner, class_name: 'Member'
belongs_to :plant_part
default_scope { order('created_at DESC') }
validates :crop, approved: true

View File

@@ -1,5 +1,5 @@
class Photo < ActiveRecord::Base
ON_MODELS = %w(plantings harvests gardens)
ON_MODELS = %w(plantings harvests gardens).freeze
belongs_to :owner, class_name: 'Member'
ON_MODELS.each do |relation|
@@ -13,7 +13,7 @@ class Photo < ActiveRecord::Base
def relationships
associations = []
ON_MODELS.each do |association_name, _reflection|
associations << self.send("#{association_name}").to_a
associations << self.send(association_name.to_s).to_a
end
associations.flatten!
end