Skip to content

Screenplay AutoMap: control default property mapping

AutoMap copies compatible event properties into same-named read model properties in a Screenplay projection. It is enabled by default, so you can concentrate explicit assignments on renamed values, constants and metadata rather than repeat every direct mapping.

Use no automap when you want to choose every mapped value yourself. It changes property mapping, not the key that selects the instance to update.

A from block can rely on matching properties without listing them:

projection User => UserReadModel
from UserRegistered
IsActive = true

Compatible properties such as name and email map to Name and Email without assignments. IsActive is explicitly set to true, so an event value with that name cannot overwrite it. Matching is case-insensitive.

Use no automap to disable automatic property mapping when needed.

Disable AutoMap for the entire projection:

projection User => UserReadModel
no automap
from UserRegistered
Name = name
Email = email

At this level, only the explicit Name and Email assignments map event values. An inner scope that supports an AutoMap setting can opt back in with automap.

Disable AutoMap inside an every or all block:

projection User => UserReadModel
every
no automap
LastUpdated = $eventContext.occurred

This disables the automatic contribution of that every or all block; it does not disable AutoMap for separate from handlers. Neither automap nor no automap is accepted inside a from block (PLAY0075). Set the policy on the projection or a supported enclosing scope instead.

Disable AutoMap within a join’s with blocks:

join Group on GroupId
with GroupCreated
no automap
Name = name
with GroupRenamed
no automap
Name = name

Disable AutoMap for children collections:

children members identified by userId
no automap
from UserAddedToGroup
UserId = userId
Role = role

An explicit mapping reserves its target property, so AutoMap leaves that target alone:

from UserRegistered
IsActive = true
CreatedAt = $eventContext.occurred

If the event has compatible Name and Email properties, AutoMap supplies them. The explicit mappings decide IsActive and CreatedAt, regardless of same-named event values.

AutoMap matches event and read model property names using an ordinal, case-insensitive comparison. A target must exist, accept the source type and have no explicit mapping.

In scoped executable semantics, types must match in kind, primitive or declared type, and collection shape; an optional source cannot fill a required target. Chronicle’s runtime conversion is not a promise that the Screenplay semantic model can bind every conversion.

There are two further exclusions: a from block containing only counter or arithmetic operations does not auto-map other properties, and join AutoMap does not reuse an event property already consumed by an explicit join mapping.

Consider a UserRegistered event with the properties Name, Email, and Age, projected onto a read model with the properties Name, Email, Age, and IsActive:

projection User => UserReadModel
from UserRegistered
IsActive = true

With compatible types, Name, Email and Age are copied automatically. The explicit IsActive assignment supplies a value the event does not carry.

The projection setting supplies the default for scopes without an explicit policy. every and all can set their own policy, as can each join with block and each children or nested block. Use no automap to disable matching there, or automap to enable it despite a disabled default.

Explicit mappings take precedence at every level. A from block inherits its scope’s policy; putting an AutoMap directive inside it reports PLAY0075.

projection Product => ProductReadModel
from ProductCreated
# Name, Price, Description auto-mapped if they exist
CreatedAt = $eventContext.occurred
projection Order => OrderReadModel
no automap
from OrderPlaced
OrderId = orderId
CustomerId = customerId
Total = total
Status = "Pending"
projection User => UserReadModel
from UserRegistered
# AutoMap enabled (default)
IsActive = true
join Profile on ProfileId
with UserProfileUpdated
no automap
# Must map everything explicitly
Name = fullName
Email = emailAddress

Projection-Level Disable Inherited by Every Event

Section titled “Projection-Level Disable Inherited by Every Event”
projection User => UserReadModel
no automap
from UserRegistered
Name = name
Email = email
from UserDeactivated
# Still disabled - no automap is inherited
IsActive = false
DeactivatedAt = $eventContext.occurred
projection Order => OrderReadModel
from OrderPlaced
# AutoMap enabled
join Customer on CustomerId
with CustomerCreated
no automap
CustomerName = name
with CustomerUpdated
no automap
CustomerName = name
projection Group => GroupReadModel
from GroupCreated
# AutoMap enabled
children members identified by userId
no automap
from UserAddedToGroup
UserId = userId
Status = "Active"

Keep AutoMap when shared names represent the same values and compatible types. A few renamed or formatted fields do not require disabling it: map those targets explicitly and let the remaining direct matches stay automatic.

Disable it when the projection should state every value it accepts from an event. This can make a deliberate mapping boundary easier to review, especially when similarly named properties do not mean the same thing.

Review name matches as part of the projection’s behavior. Adding a same-named event or read model property can add an automatic mapping; write an explicit assignment or disable matching if that would be the wrong result.

If only some from handlers need fully explicit mappings, disable AutoMap on their shared projection or child scope and write the assignments there. There is no per-from toggle. Continue with Property Mapping for renamed values, clearing and metadata assignments.

An automap directive is redundant where it only repeats the enabled default. Keep it where it deliberately overrides no automap from the projection. Do not infer a disabled policy from the absence of an old directive: inspect the mappings and choose which values should be copied.

Existing explicit mappings continue to take precedence. If you need to preserve an explicit-only mapping policy, add no automap at the appropriate scope and retain those assignments.