@@ -334,7 +334,7 @@ We also need to sort our queries, so let's do this now!
334
334
The method we want to use now is `orderBy`. The arguments are the names of the properties we want to sort.
335
335
We can pass as many arguments as we want.
336
336
337
-
**Single Sort**
337
+
#### Single Sort
338
338
339
339
We can sort our **Posts** by the `created_at` date:
340
340
@@ -355,7 +355,7 @@ We can sort our **Posts** by the `created_at` date:
355
355
</code-block>
356
356
</code-group>
357
357
358
-
**Multiple Sort**
358
+
#### Multiple Sort
359
359
360
360
And we can sort by their `title` too:
361
361
@@ -380,27 +380,73 @@ And we can sort by their `title` too:
380
380
Sorting is ascending by default and can be reversed by adding a hyphen (-) to the start of the property name.
381
381
</alert>
382
382
383
+
#### Using an Array
384
+
385
+
<alert type="success">Available in version >= v1.8.0</alert>
386
+
387
+
The first argument of `orderBy` also accepts an array of string.
388
+
389
+
<code-group>
390
+
<code-block label="Query" active>
391
+
392
+
```js
393
+
const posts = await Post.orderBy(['-created_at', 'title']).get()
394
+
```
395
+
396
+
</code-block>
397
+
<code-block label="Request">
398
+
399
+
```http request
400
+
GET /posts?sort=-created_at
401
+
```
402
+
403
+
</code-block>
404
+
</code-group>
405
+
383
406
## Including Relationships
384
407
385
408
See the [API reference](/api/query-builder-methods#include)
386
409
387
410
Sometimes, we will want to eager load a relationship, and to do so, we can use the `include` method.
388
411
The arguments are the names of the relationships we want to include. We can pass as many arguments as we want.
389
412
390
-
Let's eager load the `category` relationship of our **Post**:
413
+
Let's eager load the relationships `category` and `tags` of our **Post**:
414
+
415
+
<code-group>
416
+
<code-block label="Query" active>
417
+
418
+
```js
419
+
const posts = await Post.include('category', 'tags').get()
420
+
```
421
+
422
+
</code-block>
423
+
<code-block label="Request">
424
+
425
+
```http request
426
+
GET /posts?include=category,tags
427
+
```
428
+
429
+
</code-block>
430
+
</code-group>
431
+
432
+
#### Using an Array
433
+
434
+
<alert type="success">Available in version >= v1.8.0</alert>
435
+
436
+
The first argument of `include` also accepts an array of string.
391
437
392
438
<code-group>
393
439
<code-block label="Query" active>
394
440
395
441
```js
396
-
const posts = await Post.include('category').get()
442
+
const posts = await Post.include(['category', 'tags']).get()
397
443
```
398
444
399
445
</code-block>
400
446
<code-block label="Request">
401
447
402
448
```http request
403
-
GET /posts?include=category
449
+
GET /posts?include=category,tags
404
450
```
405
451
406
452
</code-block>
@@ -413,20 +459,43 @@ See the [API reference](/api/query-builder-methods#append)
413
459
We can also append attributes to our queries using the `append` method.
414
460
The arguments are the names of the attributes we want to append. We can pass as many arguments as we want.
415
461
416
-
Let's append the `likes` attribute of our **Post**:
462
+
Let's append the attribute `likes` and `shares` of our **Post**:
463
+
464
+
<code-group>
465
+
<code-block label="Query" active>
466
+
467
+
```js
468
+
const posts = await Post.append('likes', 'shares').get()
469
+
```
470
+
471
+
</code-block>
472
+
<code-block label="Request">
473
+
474
+
```http request
475
+
GET /posts?append=likes,shares
476
+
```
477
+
478
+
</code-block>
479
+
</code-group>
480
+
481
+
#### Using an Array
482
+
483
+
<alert type="success">Available in version >= v1.8.0</alert>
484
+
485
+
The first argument of `append` also accepts an array of string.
417
486
418
487
<code-group>
419
488
<code-block label="Query" active>
420
489
421
490
```js
422
-
const posts = await Post.append('likes').get()
491
+
const posts = await Post.append(['likes', 'shares']).get()
423
492
```
424
493
425
494
</code-block>
426
495
<code-block label="Request">
427
496
428
497
```http request
429
-
GET /posts?append=likes
498
+
GET /posts?append=likes,shares
430
499
```
431
500
432
501
</code-block>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4