Class: Sequent::Core::CommandRecord
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Sequent::Core::CommandRecord
- 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
- #origin_command ⇒ Object (also: #origin)
-
#parent_event ⇒ Object
(also: #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.
Methods included from SerializesCommand
Instance Method Details
#origin_command ⇒ Object 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_event ⇒ Object 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 |