@@ -123,19 +123,12 @@ module Fresh = QlBuiltins::NewEntity<TAddedElement>;
123123Using an algebraic data type with multiple constructors allows several distinct
124124entities to be created for the same source entity.
125125
126- The query is compiled against the source schema, so a fresh ID cannot belong to
127- an entity type that exists only in the target schema. Define a union of the
128- appropriate source-schema type and ` Fresh::EntityId ` , then use a class extending
129- that union in the output predicates:
126+ The query is compiled against the source schema, so its static QL types cannot
127+ refer to an entity type that exists only in the target schema. An output column
128+ that contains only fresh IDs can use ` Fresh::EntityId ` directly:
130129
131130``` ql
132- class TNewElement = @element or Fresh::EntityId;
133-
134- class NewElement extends TNewElement {
135- string toString() { none() }
136- }
137-
138- query predicate new_wrappers(NewElement wrapper, Element element) {
131+ query predicate new_wrappers(Fresh::EntityId wrapper, Element element) {
139132 wrapper = Fresh::map(TWrapper(element))
140133}
141134```
@@ -146,13 +139,26 @@ Run the predicate to populate a relation in the target schema:
146139wrappers.rel: run upgrade.qlo new_wrappers
147140```
148141
149- The target relation's column type determines the database type of each fresh
150- ID. Emit every target relation needed to describe the new entity, including
151- relationships such as its parent, location, or type. When rewriting an existing
152- relation, its output predicate will usually need to preserve all existing rows
153- as well as add rows containing the fresh IDs. Reuse the same
154- ` Fresh::map(...) ` expression in each predicate that refers to a particular new
155- entity.
142+ If an output column can contain both existing source IDs and fresh IDs, define a
143+ union of the source-schema type and ` Fresh::EntityId ` , then use a class extending
144+ that union as the column's static QL type:
145+
146+ ``` ql
147+ class TExistingOrFreshElement = @element or Fresh::EntityId;
148+
149+ class ExistingOrFreshElement extends TExistingOrFreshElement {
150+ string toString() { none() }
151+ }
152+ ```
153+
154+ These QL types only describe values while evaluating the transformation against
155+ the source schema. The corresponding column type in the target database schema
156+ determines the database type assigned to each fresh ID. Emit every target
157+ relation needed to describe the new entity, including relationships such as its
158+ parent, location, or type. When rewriting an existing relation, its output
159+ predicate will usually need to preserve all existing rows as well as add rows
160+ containing the fresh IDs. Reuse the same ` Fresh::map(...) ` expression in each
161+ predicate that refers to a particular new entity.
156162
157163### Testing your scripts
158164
0 commit comments