Commit 40086791 by Ivan Lan

fix pasted with any if arg is empty array

parent 23a9a168
......@@ -9,6 +9,7 @@ module ActsAsPasting
# ary => [obj, obj]
scope :pasted_with_any, ->(ary, prefix: '') {
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)}")
source_arel = arel_table
join_condition = ary.group_by(&:first).map do |(klass, value)|
......@@ -68,14 +69,14 @@ module ActsAsPasting
remove_ary.each { |klass, id| pastings.where(
type: '',
pasted: self,
pasteable_type: klass,
pasteable_type: klass,
pasteable_id: id
).destroy_all
}
add_ary.each { |klass, id| pastings.create!(
type: '',
pasted: self,
pasteable_type: klass,
pasted: self,
pasteable_type: klass,
pasteable_id: id
)
}
......@@ -85,7 +86,7 @@ module ActsAsPasting
# def method_missing name, *arg, &block
# klass_downcase = /^paste_(.+)_list$/.match(name)&.[](1)
# if klass_downcase
# downcase_all_combination(klass_downcase).each do |str|
# return paste_list_for(str) if correct_class_name?(str)
......@@ -150,7 +151,7 @@ module ActsAsPasting
end
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}"
}
if new_record?
......@@ -166,14 +167,14 @@ module ActsAsPasting
remove_ary.each { |klass, id| pastings.where(
type: "#{type_value}",
pasted: self,
pasteable_type: klass,
pasteable_type: klass,
pasteable_id: id
).destroy_all
}
add_ary.each { |klass, id| pastings.create!(
type: "#{type_value}",
pasted: self,
pasteable_type: klass,
pasted: self,
pasteable_type: klass,
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