module Polo::SqlTranslator::ActiveRecordFour

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.

Public Instance Methods

insert_values(record) click to toggle source
# 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