module Polo::SqlTranslator::ActiveRecordFive

Internal: Returns an object's attribute definitions along with their set values (for Rails >= 5.x).

Serializers have changed again in rails 5. We now use the type_caster from the arel_table.

Public Instance Methods

raw_sql(record) click to toggle source

Based on the codepath used in Rails 5

# File lib/polo/sql_translator.rb, line 91
def raw_sql(record)
  values = record.send(:arel_attributes_with_values_for_create, record.attribute_names)
  model = record.class
  substitutes, binds = model.unscoped.substitute_values(values)

  insert_manager = model.arel_table.create_insert
  insert_manager.insert substitutes

  model.connection.unprepared_statement do
    model.connection.to_sql(insert_manager, binds)
  end
end