Entities are identity; components carry the state and behaviour. It reads like plain Rails.
Published
Edit
Composable domain models
How this works
♥ Like runs post.likes_counter.increment!. The first like inserts a
counters row in slot likes, and each later like updates it. Before the
first like there is no row at all: the count you see is the column default, 0.
Publish now transitions the State in slot publish. The
author is a row in the shared relationships table, not a column on the post.
The declaration · app/entities/post.rb
component Text, prefix: :title # post.title (the String), post.title_text (the Text)
component Text, prefix: :body # post.body
component State, prefix: :publish, states: %w[draft published] # post.publish_state.status
component Counter, prefix: :likes # post.likes (the Integer), post.likes_counter
component SearchVector # rebuilt by Demo::Indexer from the post's Texts
relates_to :author, User # post.author => User
has_many :comments, via: :post, dependent: :destroy # post.comments
The rows behind it
| Where | Row |
|---|---|
entities |
|
texts
slot title
|
|
texts
slot body
|
|
states
slot publish
|
|
counters
slot likes
|
|
search_vectors
default slot
|
Not read by this page, so not queried |
relationships
slot author
|
|
Every slot row also has id, entity_id (this
entity's id) and timestamps. Ids are cut to their first block. The rows are the ones this page loaded,
so the panel adds no queries.
This finally makes the pattern click.