Order query results based on a field name and an optional direction. * * await Flight.orderBy("departure").all(); * * await Flight.orderBy("departure", "desc").all(); * * await Flight.orderBy({ departure: "desc", destination: "asc" }).all();
(
this: T,
fieldOrFields: string | OrderByClauses,
orderDirection: OrderDirection = "asc",
)
| 490 | * await Flight.orderBy({ departure: "desc", destination: "asc" }).all(); |
| 491 | */ |
| 492 | static orderBy<T extends ModelSchema>( |
| 493 | this: T, |
| 494 | fieldOrFields: string | OrderByClauses, |
| 495 | orderDirection: OrderDirection = "asc", |
| 496 | ) { |
| 497 | if (typeof fieldOrFields === "string") { |
| 498 | this._currentQuery.orderBy( |
| 499 | this.formatFieldToDatabase(fieldOrFields) as string, |
| 500 | orderDirection, |
| 501 | ); |
| 502 | } else { |
| 503 | for ( |
| 504 | const [field, orderDirectionField] of Object.entries( |
| 505 | fieldOrFields, |
| 506 | ) |
| 507 | ) { |
| 508 | this._currentQuery.orderBy( |
| 509 | this.formatFieldToDatabase(field) as string, |
| 510 | orderDirectionField, |
| 511 | ); |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | return this; |
| 516 | } |
| 517 | |
| 518 | /** Group rows by a given field. |
| 519 | * |
no test coverage detected