Skip to content

Commit bdaefdf

Browse files
authored
docs: Added warning for using ignoreConflicts on models with non persistant fields (#436)
1 parent 76502d1 commit bdaefdf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

docs/06-concepts/06-database/05-crud.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,25 @@ In previous versions of Serverpod the `insert` method mutated the input object b
4545

4646
### Ignoring conflicts
4747

48-
When inserting rows that might violate a unique or exclusion constraint, you can set `ignoreConflicts` to `true` on the `insert` method. Rows that would cause a unique constraint violation are silently skipped, and only the non-conflicting rows are inserted.
48+
When inserting rows that might violate a unique or exclusion constraint, you can set `ignoreConflicts` to `true` on the `insert` method. Rows that would cause a unique or exclusion constraint violation are silently skipped, and only the non-conflicting rows are inserted.
4949

5050
```dart
5151
var rows = [Company(name: 'Serverpod'), Company(name: 'Google')];
5252
var inserted = await Company.db.insert(session, rows, ignoreConflicts: true);
5353
```
5454

55-
The method returns only the rows that were successfully inserted. If all rows conflict, an empty list is returned.
55+
The method returns only the rows that were successfully inserted. If all rows conflict, an empty list is returned. Unlike a regular `insert`, which fails entirely if any row violates a constraint, `ignoreConflicts` allows partial inserts where only the non-conflicting rows are written.
5656

5757
This is useful for idempotent operations where you want to insert data without failing on duplicates.
5858

5959
:::note
6060
Under the hood, this uses PostgreSQL's `ON CONFLICT DO NOTHING`. Only unique and exclusion constraint violations are ignored — other errors such as `NOT NULL`, `CHECK`, or foreign key violations will still throw an exception.
6161
:::
6262

63+
:::warning
64+
When using `ignoreConflicts` with models that have [non-persistent fields](models#non-persistent-fields), each row is inserted individually instead of in a single batch. This is necessary because the database cannot report which rows were skipped in a batch insert, making it impossible to correctly match non-persistent field values back to inserted rows. For large numbers of rows, this can cause performance issues. Consider removing non-persistent fields from the model or inserting in smaller batches.
65+
:::
66+
6367
## Read
6468

6569
There are three different read operations available.

0 commit comments

Comments
 (0)