Skip to content

Commit f736273

Browse files
authored
Merge pull request #10532 from dahfjkg/dat/oql-insert-associations
Add insert of associations to OQL statement doc
2 parents 4ed7004 + 5160a79 commit f736273

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,32 @@ Available from Mendix version 11.6.0
173173
The syntax of `INSERT` statements is:
174174

175175
```sql
176-
INSERT INTO <entity> ( <attribute> [ , …n ] ) <oql-query>
176+
INSERT INTO <entity> ( <attribute | <association> [ , …n ] ) <oql-query>
177177
```
178178

179179
* `entity` is the entity for which new objects will be created.
180180

181181
* `attribute` is an attribute of the entity that will be inserted.
182182

183-
* `oql-query` is any OQL query that returns same number of columns as the number of attributes that will be inserted.
183+
* `association` is an association to an existing object of associated entity. Associations can be inserted in Mendix version 11.7.0 and above.
184+
185+
* `oql-query` is any OQL query that returns same number of columns as the number of attributes and associations that will be inserted.
184186
This query can select data from persistable entities and/or [view entities](/refguide/view-entities/).
185187

186188
Example:
187189

188190
```sql
189-
INSERT INTO Module.Order ( OrderNumber, CustomerNumber )
190-
SELECT NewOrderNumber, Loader.TemporaryData_Customer/Loader.Customer/Number FROM Loader.TemporaryData
191+
INSERT INTO Module.Order ( OrderNumber, CustomerNumber, Module.Order_Customer )
192+
SELECT NewOrderNumber, Loader.TemporaryData_Customer/Loader.Customer/Number, Loader.TemporaryData_Customer FROM Loader.TemporaryData
191193
```
192194

193195
### OQL `INSERT` Limitations
194196

195-
* It is not yet possible to insert associations. As a workaround, they can be added after the `INSERT` using an OQL `UPDATE` statement.
197+
* Only a single value can be specified per association.
198+
199+
If you need to set multiple values in a many-to-many association, we recommend doing that in two stages. First, use `INSERT` to create required objects and then set associations using `UPDATE`.
196200
* Attributes of type "Date and time" with a default value of `'[%CurrentDateTime%]'` will not have their default values set when the `INSERT` statement does not specify them.
201+
197202
As a workaround, explicitly insert the attribute with a value of `'[%CurrentDatetime%]'` in the `SELECT` part.
198203
* When using Oracle, due to database limitations, inserting attributes of type unlimited string or binary is not supported.
199204
* The general limitations for OQL statements also apply. See [General Limitations for OQL Statements](#oql-limitations), below.

0 commit comments

Comments
 (0)