Commit 40086791 by Ivan Lan

fix pasted with any if arg is empty array

parent 23a9a168
...@@ -9,6 +9,7 @@ module ActsAsPasting ...@@ -9,6 +9,7 @@ module ActsAsPasting
# ary => [obj, obj] # ary => [obj, obj]
scope :pasted_with_any, ->(ary, prefix: '') { scope :pasted_with_any, ->(ary, prefix: '') {
ary = parsed_condition_ary(ary) ary = parsed_condition_ary(ary)
return none unless ary.first
arel = Arel::Table.new(:acts_as_pasting_pastings, as: "acts_as_pasting_pastings_#{SecureRandom.hex(10)}") arel = Arel::Table.new(:acts_as_pasting_pastings, as: "acts_as_pasting_pastings_#{SecureRandom.hex(10)}")
source_arel = arel_table source_arel = arel_table
join_condition = ary.group_by(&:first).map do |(klass, value)| join_condition = ary.group_by(&:first).map do |(klass, value)|
...@@ -68,14 +69,14 @@ module ActsAsPasting ...@@ -68,14 +69,14 @@ module ActsAsPasting
remove_ary.each { |klass, id| pastings.where( remove_ary.each { |klass, id| pastings.where(
type: '', type: '',
pasted: self, pasted: self,
pasteable_type: klass, pasteable_type: klass,
pasteable_id: id pasteable_id: id
).destroy_all ).destroy_all
} }
add_ary.each { |klass, id| pastings.create!( add_ary.each { |klass, id| pastings.create!(
type: '', type: '',
pasted: self, pasted: self,
pasteable_type: klass, pasteable_type: klass,
pasteable_id: id pasteable_id: id
) )
} }
...@@ -85,7 +86,7 @@ module ActsAsPasting ...@@ -85,7 +86,7 @@ module ActsAsPasting
# def method_missing name, *arg, &block # def method_missing name, *arg, &block
# klass_downcase = /^paste_(.+)_list$/.match(name)&.[](1) # klass_downcase = /^paste_(.+)_list$/.match(name)&.[](1)
# if klass_downcase # if klass_downcase
# downcase_all_combination(klass_downcase).each do |str| # downcase_all_combination(klass_downcase).each do |str|
# return paste_list_for(str) if correct_class_name?(str) # return paste_list_for(str) if correct_class_name?(str)
...@@ -150,7 +151,7 @@ module ActsAsPasting ...@@ -150,7 +151,7 @@ module ActsAsPasting
end end
def paste_#{downcase}_list= ary, run_save: true def paste_#{downcase}_list= ary, run_save: true
ary = self.class.parsed_condition_ary(ary).select { |a| ary = self.class.parsed_condition_ary(ary).select { |a|
a.first == "#{base_class_name}" a.first == "#{base_class_name}"
} }
if new_record? if new_record?
...@@ -166,14 +167,14 @@ module ActsAsPasting ...@@ -166,14 +167,14 @@ module ActsAsPasting
remove_ary.each { |klass, id| pastings.where( remove_ary.each { |klass, id| pastings.where(
type: "#{type_value}", type: "#{type_value}",
pasted: self, pasted: self,
pasteable_type: klass, pasteable_type: klass,
pasteable_id: id pasteable_id: id
).destroy_all ).destroy_all
} }
add_ary.each { |klass, id| pastings.create!( add_ary.each { |klass, id| pastings.create!(
type: "#{type_value}", type: "#{type_value}",
pasted: self, pasted: self,
pasteable_type: klass, pasteable_type: klass,
pasteable_id: id pasteable_id: id
) )
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment