Class: ActiveRecord::Base::PromiscuousInsertOperation

Inherits:
PromiscousOperation show all
Defined in:
lib/promiscuous/publisher/operation/active_record.rb

Instance Attribute Summary

Attributes inherited from Promiscuous::Publisher::Operation::NonPersistent

#instances

Attributes inherited from Promiscuous::Publisher::Operation::Base

#operation

Instance Method Summary collapse

Methods inherited from PromiscousOperation

#ensure_transaction!, #execute, #model, #operation_payloads, #transaction_context

Methods inherited from Promiscuous::Publisher::Operation::NonPersistent

#execute_instrumented, #operation_payloads, #query_dependencies

Methods inherited from Promiscuous::Publisher::Operation::Base

_acquire_lock, #acquire_op_lock, #dependencies_for, #dependency_for_op_lock, #ensure_op_still_locked, #execute, #execute_instrumented, #explain_operation, #generate_payload, #get_new_op_lock, #increment_dependencies, lock_options, #on_rabbitmq_confirm, #operation_payloads, #payload_for, #publish_payload_in_rabbitmq_async, #publish_payload_in_redis, #query_dependencies, rabbitmq_staging_set_key, #record_timestamp, #recover_db_operation, recover_locks, recover_operation, recover_operation_from_lock, recover_payloads_for_rabbitmq, #recovering?, #recovery_payload, register_recovery_mechanism, #release_op_lock, run_recovery_mechanisms, #should_instrument_query?, #trace_operation, #write_dependencies

Constructor Details

#initialize(arel, name, pk, id_value, sequence_name, binds, options = {}) ⇒ PromiscuousInsertOperation

Returns a new instance of PromiscuousInsertOperation.



188
189
190
191
192
193
194
195
# File 'lib/promiscuous/publisher/operation/active_record.rb', line 188

def initialize(arel, name, pk, id_value, sequence_name, binds, options={})
  super(arel, name, binds, options)
  @pk = pk
  @id_value = id_value
  @sequence_name = sequence_name
  @operation = :create
  raise unless @arel.is_a?(Arel::InsertManager)
end

Instance Method Details

#db_operation_and_selectObject



197
198
199
200
201
202
203
204
205
# File 'lib/promiscuous/publisher/operation/active_record.rb', line 197

def db_operation_and_select
  # XXX This is only supported by Postgres and should be in the postgres driver

  @connection.exec_insert("#{@connection.to_sql(@arel, @binds)} RETURNING *", @operation_name, @binds).tap do |result|
    @instances = result.map { |row| model.instantiate(row) }
  end
  # TODO Use correct primary key
  @instances.first.id
end