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.
Default Behavior
Section titled “Default Behavior”A from block can rely on matching properties without listing them:
projection User => UserReadModel from UserRegistered IsActive = trueCompatible 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.
Disabling AutoMap
Section titled “Disabling AutoMap”Use no automap to disable automatic property mapping when needed.
Projection-Level Disable
Section titled “Projection-Level Disable”Disable AutoMap for the entire projection:
projection User => UserReadModel no automap
from UserRegistered Name = name Email = emailAt 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.
Every- and All-Level Disable
Section titled “Every- and All-Level Disable”Disable AutoMap inside an every or all block:
projection User => UserReadModel every no automap LastUpdated = $eventContext.occurredThis 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.
Join-Level Disable
Section titled “Join-Level Disable”Disable AutoMap within a join’s with blocks:
join Group on GroupId with GroupCreated no automap Name = name with GroupRenamed no automap Name = nameChildren-Level Disable
Section titled “Children-Level Disable”Disable AutoMap for children collections:
children members identified by userId no automap
from UserAddedToGroup UserId = userId Role = roleCombining with Explicit Mappings
Section titled “Combining with Explicit Mappings”An explicit mapping reserves its target property, so AutoMap leaves that target alone:
from UserRegistered IsActive = true CreatedAt = $eventContext.occurredIf the event has compatible Name and Email properties, AutoMap supplies them. The explicit mappings decide IsActive and CreatedAt, regardless of same-named event values.
Matching Rules
Section titled “Matching Rules”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 = trueWith compatible types, Name, Email and Age are copied automatically. The explicit IsActive assignment supplies a value the event does not carry.
Scope and Precedence
Section titled “Scope and Precedence”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.
Examples
Section titled “Examples”Default AutoMap
Section titled “Default AutoMap”projection Product => ProductReadModel from ProductCreated # Name, Price, Description auto-mapped if they exist CreatedAt = $eventContext.occurredDisable AutoMap Entirely
Section titled “Disable AutoMap Entirely”projection Order => OrderReadModel no automap
from OrderPlaced OrderId = orderId CustomerId = customerId Total = total Status = "Pending"Mixed Approach
Section titled “Mixed Approach”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 = emailAddressProjection-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.occurredJoin with Disabled AutoMap
Section titled “Join with Disabled AutoMap”projection Order => OrderReadModel from OrderPlaced # AutoMap enabled
join Customer on CustomerId with CustomerCreated no automap CustomerName = name with CustomerUpdated no automap CustomerName = nameChildren with Selective Disable
Section titled “Children with Selective Disable”projection Group => GroupReadModel from GroupCreated # AutoMap enabled
children members identified by userId no automap
from UserAddedToGroup UserId = userId Status = "Active"When to Disable AutoMap
Section titled “When to Disable AutoMap”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.
Best Practices
Section titled “Best Practices”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.
Migration from Explicit AutoMap
Section titled “Migration from Explicit AutoMap”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.