Class: Sequent::Core::CommandRecord

Inherits:
ApplicationRecord show all
Includes:
SerializesCommand
Defined in:
lib/sequent/core/command_record.rb

Overview

For storing Sequent::Core::Command in the database using active_record

Instance Method Summary collapse

Methods included from SerializesCommand

#command, #command=

Instance Method Details

#origin_commandObject Also known as: origin



67
68
69
# File 'lib/sequent/core/command_record.rb', line 67

def origin_command
  parent_event&.parent_command&.origin_command || self
end

#parent_eventObject Also known as: parent

A ‘belongs_to` association fails in weird ways with ActiveRecord 7.1, probably due to the use of composite primary keys so use an explicit query here and cache the result.



61
62
63
64
65
# File 'lib/sequent/core/command_record.rb', line 61

def parent_event
  return nil unless event_aggregate_id && event_sequence_number

  @parent_event ||= EventRecord.find_by(aggregate_id: event_aggregate_id, sequence_number: event_sequence_number)
end