Skip to content

Commit

Permalink
mix multiple matches assignment (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjansing committed Sep 11, 2015
1 parent 3a037c1 commit 19a5ba9
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/models/concept/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,25 @@ class Concept::Base < ActiveRecord::Base

if (@inline_matches ||= {}).any?
@inline_matches.each do |match_class, urls|
# temp array to check existing match-urls
# we cannot use @inline_matches (call by reference)
urls_copy = urls.dup

# destroy old relations
self.send(match_class.to_relation_name).each do |match|
if (urls.include?(match.value))
urls.delete(match.value) # We're done with that one
if (urls_copy.include?(match.value))
urls_copy.delete(match.value) # We're done with that one
else
self.send(match_class.to_relation_name).destroy(match.id) # User deleted this one

# TODO: error handling job creation, check _custom param
job = self.reverse_match_service.build_job(:remove_match, self, match.value, match_class)
self.reverse_match_service.add(job)
end
end

# create new match relations
urls.each do |url|
urls_copy.each do |url|
self.send(match_class.to_relation_name) << match_class.constantize.new(value: url)
self.save

Expand Down

0 comments on commit 19a5ba9

Please sign in to comment.