class Sequent::Core::Projector

Projectors listen to events and update the view state as they see fit.

Example of updating view state, in this case the InvoiceRecord table representing an Invoice

class InvoiceProjector < Sequent::Core::Projector
  manages_tables InvoiceRecord

  on InvoiceCreated do |event|
    create_record(
      InvoiceRecord,
      recipient: event.recipient,
      amount: event.amount
    )
  end
end

Please note that the actual storage is abstracted away in the persistors. Due to this abstraction you can not traverse persist or traverse child objects like you are used to do with ActiveRecord. The following example will not work:

invoice_record.line_item_records << create_record(LineItemRecord, ...)

In this case you should simply do:

create_record(LineItemRecord, invoice_id: invoice_record.aggregate_id)