You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/06-concepts/06-database/05-crud.md
+14-5Lines changed: 14 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -231,26 +231,35 @@ The input object needs to have the `id` field set. The `deleteRow` method return
231
231
232
232
### Delete several rows
233
233
234
-
To batch delete several rows, use the `delete` method.
234
+
To batch delete several rows, use the `delete` method. This method also supports [ordering](sort) the returned deleted results.
235
235
236
236
```dart
237
-
var companiesDeleted = await Company.db.delete(session, companies);
237
+
var companiesDeleted = await Company.db.delete(
238
+
session,
239
+
companies,
240
+
orderBy: (t) => t.id,
241
+
orderDescending: false,
242
+
);
238
243
```
239
244
240
-
This is an atomic operation, meaning no entries will be deleted if any entry fails to be deleted. The `delete` method returns a `List` of the models deleted.
245
+
This is an atomic operation, meaning no entries will be deleted if any entry fails to be deleted. The `delete` method returns a `List` of the models deleted, ordered as specified by the orderBy.
241
246
242
247
### Delete by filter
243
248
244
-
You can also do a [filtered](filter) delete and delete all entries matching a `where` query, by using the `deleteWhere` method.
249
+
You can also do a [filtered](filter) delete and delete all entries matching a `where` query, by using the `deleteWhere` method. This method also supports [ordering](sort) of the returned deleted results.
245
250
246
251
```dart
247
252
var companiesDeleted = await Company.db.deleteWhere(
248
253
session,
249
254
where: (t) => t.name.like('%Ltd'),
255
+
orderByList: (t) => [
256
+
Order(column: t.name, orderDescending: true),
257
+
Order(column: t.id),
258
+
],
250
259
);
251
260
```
252
261
253
-
The above example will delete any row that ends in _Ltd_. The `deleteWhere` method returns a `List` of the models deleted.
262
+
The above example will delete any row where the `name` ends in _Ltd_. The `deleteWhere` method returns a `List` of the models deleted, ordered by name in descending order, followed by id in ascending order.
0 commit comments