Module: Polo::SqlTranslator::ActiveRecordFourOrGreater
- Included in:
- Polo::SqlTranslator
- Defined in:
- lib/polo/sql_translator.rb
Overview
Internal: Returns an object’s attribute definitions along with their set values (for Rails >= 4.x).
From Rails 4.2 onwards, for some reason attributes with custom serializers wouldn’t be properly serialized automatically. That’s why explict ‘type_cast’ call are necessary.
Instance Method Summary collapse
Instance Method Details
#insert_values(record) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/polo/sql_translator.rb', line 73 def insert_values(record) connection = ActiveRecord::Base.connection values = record.send(:arel_attributes_with_values_for_create, record.attribute_names) values.each do |attribute, value| column = record.send(:column_for_attribute, attribute.name) values[attribute] = connection.type_cast(value, column) end end |