Skip to content

Commit

Permalink
Fix: ignore virtual attributes on serialization
Browse files Browse the repository at this point in the history
ActsAsTaggable wrote a own pseudo column into the attributes hash
  • Loading branch information
chooselife22 authored and zealot128 committed Oct 29, 2019
1 parent 7854221 commit ac88b32
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/polo/adapters/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class MySQL
def on_duplicate_key_update(inserts, records)
insert_and_record = inserts.zip(records)
insert_and_record.map do |insert, record|
attrs = record.is_a?(Hash) ? record.fetch(:values) : record.attributes
attrs = record.is_a?(Hash) ? record.fetch(:values) : record.attributes.slice(*record.class.column_names)
values_syntax = attrs.keys.map do |key|
"`#{key}` = VALUES(`#{key}`)"
end
Expand All @@ -22,4 +22,4 @@ def ignore_transform(inserts, records)
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/polo/adapters/postgres.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def add_upsert_to_insert(insert, record)
return naive_update_insert(insert, record)
end

attrs = record.is_a?(Hash) ? record.fetch(:values) : record.attributes
attrs = record.is_a?(Hash) ? record.fetch(:values) : record.attributes.slice(*record.class.column_names)
values_syntax = attrs.keys.reject { |key| key.to_s == 'id' }.map do |key|
%{"#{key}" = EXCLUDED."#{key}"}
end
Expand All @@ -33,7 +33,7 @@ def add_upsert_to_insert(insert, record)
def naive_update_insert(insert, record)
table_name, id = table_name_and_key_for(record)

attrs = record.is_a?(Hash) ? record.fetch(:values) : record.attributes_before_type_cast
attrs = record.is_a?(Hash) ? record.fetch(:values) : record.attributes_before_type_cast.slice(*record.class.column_names)
updates = attrs.except('id').map do |key, value|
column = ActiveRecord::Base.connection.send(:quote_column_name, key)

Expand Down

0 comments on commit ac88b32

Please sign in to comment.