Skip to content

Commit aa9755b

Browse files
committed
Add example of association update
1 parent 4aacb6b commit aa9755b

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

content/en/docs/refguide/modeling/domain-model/oql/oql-clauses.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ It is possible to use more complex expressions in `SELECT`. This is explained in
199199

200200
It is also possible to use a subquery. See [Subquery in `SELECT`](/refguide/oql-clauses/#subquery-in-select) for more details.
201201

202-
### Selecting Attributes over Associations
202+
### Selecting Attributes over Associations {#longpath}
203203

204204
A unique feature of OQL is the ability to access attributes of associated objects using paths. For example:
205205

content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ This does not apply to the `=` and `!=` operators. Handling of `NULL` in [other
672672

673673
In some databases, using `STRING` type variables in place of numeric, `DATETIME` or `BOOLEAN` values in operators and functions that explicitly require those types, causes the database to perform an implicit conversion. A common example would be the use of a `STRING` representation of a `DATETIME` variable inside a `DATEPART` function. Mendix recommends that you always [cast](#cast) strings to the exact type the operator or functions.
674674

675-
## Functions
675+
## Functions {#functions}
676676

677677
These are the currently supported functions:
678678

content/en/docs/refguide/modeling/domain-model/oql/oql-statements.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ The syntax of `UPDATE` statements is:
6666

6767
```sql
6868
UPDATE <entity>
69-
SET { <attribute> = <expression> } [ ,...n ]
69+
SET { { <attribute> | <association> } = <expression> } [ ,...n ]
7070
WHERE <condition>
7171
```
7272

7373
`entity` is the entity whose objects are being updated.
7474

75-
`attribute` is an attribute of the entity that is being updated. Multiple attributes can be updated in the same statement.
75+
`attribute` is an attribute of the entity that is being updated. `attribute` is an association that is being updated. Multiple attributes and assosciations can be updated in the same statement.
7676

7777
`expression` is a new value of an attribute. Any [OQL expression](/refguide/oql-expressions/) is allowed. The value type of the expression should match the attribute type according to [type coercion precedence](/refguide/oql-expression-syntax/#type-coercion).
7878

@@ -89,10 +89,18 @@ SET
8989
FROM Module.Order
9090
WHERE Module.Order_Customer/Module.Customer/ID = Module.Customer/ID
9191
),
92-
Location = Module.Customer_Address/Module.Address/City,
93-
Name = UPPER(Name)
92+
Location = Module.Customer_Address/Module.Address/AddressString,
93+
Name = UPPER(Name),
94+
Module.Customer_Branch = Module.Customer_Address/Module.Address/Module.Address_City/Module.City/Module.Branch_City
9495
```
9596

97+
In the example above, attributes of entity `Module.Customer` are updated using different capabilities of `OQL UPDATE` functionality:
98+
99+
- `TotalAmount` attribute is set to a [subqery](/refguide/oql-clauses/#subquery-in-select) with aggregate function
100+
- `Location` is set to a [path](/refguide/oql-clauses/#longpath) over association to attribute
101+
- `Name` is set to a [function](/refguide/oql-expression-syntax/#functions)
102+
- Association `Module.Customer_Branch` is set to a [path](/refguide/oql-clauses/#longpath) to association
103+
96104
{{% alert color="info" %}}
97105
Updating attributes was introduced in Mendix 11.3.
98106

0 commit comments

Comments
 (0)