@@ -6,6 +6,7 @@ category: API
6
6
---
7
7
8
8
## ` include `
9
+
9
10
- Arguments: ` (...args) `
10
11
- Returns: ` self `
11
12
@@ -26,6 +27,7 @@ await Model.include(['user', 'category'])
26
27
<alert type =" info " >` with ` is an alias of this method.</alert >
27
28
28
29
## ` append `
30
+
29
31
- Arguments: ` (...args) `
30
32
- Returns: ` self `
31
33
@@ -44,17 +46,20 @@ await Model.append(['likes', 'shares'])
44
46
```
45
47
46
48
## ` select `
49
+
47
50
- Arguments: ` (...fields) `
48
51
- Returns: ` self `
49
52
50
53
Set the columns to be selected.
51
54
52
55
#### Single entity
56
+
53
57
``` js
54
58
await Model .select ([' title' , ' content' ])
55
59
```
56
60
57
61
#### Related entities
62
+
58
63
``` js
59
64
await Post .select ({
60
65
posts: [' title' , ' content' ],
@@ -63,6 +68,7 @@ await Post.select({
63
68
```
64
69
65
70
## ` where `
71
+
66
72
- Arguments: ` (field, value) `
67
73
- Returns: ` self `
68
74
@@ -89,6 +95,7 @@ await Model.where({ user: { status: 'active' } })
89
95
```
90
96
91
97
## ` whereIn `
98
+
92
99
- Arguments: ` (field, array) `
93
100
- Returns: ` self `
94
101
@@ -115,24 +122,26 @@ await Model.where({ user: { id: [1, 2, 3] } })
115
122
```
116
123
117
124
## ` orderBy `
125
+
118
126
- Arguments: ` (...args) `
119
127
- Returns: ` self `
120
128
121
129
Add an "order by" clause to the query.
122
130
123
131
``` js
124
- await Model .orderBy (' -created_at' , ' category_id' )
132
+ await Model .orderBy (' -created_at' , ' category_id' )
125
133
```
126
134
127
135
#### Array
128
136
129
137
<alert type =" success " >Available in version >= v1.8.0</alert >
130
138
131
139
``` js
132
- await Model .orderBy ([' -created_at' , ' category_id' ])
140
+ await Model .orderBy ([' -created_at' , ' category_id' ])
133
141
```
134
142
135
143
## ` page `
144
+
136
145
- Arguments: ` (value) `
137
146
- Returns: ` self `
138
147
@@ -143,6 +152,7 @@ await Model.page(1)
143
152
```
144
153
145
154
## ` limit `
155
+
146
156
- Arguments: ` (value) `
147
157
- Returns: ` self `
148
158
@@ -153,6 +163,7 @@ await Model.limit(20)
153
163
```
154
164
155
165
## ` params `
166
+
156
167
- Arguments: ` (payload) `
157
168
- Returns: ` self `
158
169
@@ -161,24 +172,25 @@ Add custom parameters to the query.
161
172
<code-group >
162
173
<code-block Label =" Query " active >
163
174
164
- ``` js
165
- await Model .params ({
166
- foo: ' bar' ,
167
- baz: true
168
- })
169
- ```
175
+ ``` js
176
+ await Model .params ({
177
+ foo: ' bar' ,
178
+ baz: true
179
+ })
180
+ ```
170
181
171
182
</code-block >
172
183
<code-block Label =" Request " >
173
184
174
- ``` http request
175
- GET /resource?foo=bar&baz=true
176
- ```
185
+ ``` http request
186
+ GET /resource?foo=bar&baz=true
187
+ ```
177
188
178
189
</code-block >
179
190
</code-group >
180
191
181
192
## ` when `
193
+
182
194
<alert type =" success " >Available in version >= v1.10.0</alert >
183
195
184
196
- Arguments: ` (value, callback) `
@@ -192,7 +204,33 @@ const search = 'foo'
192
204
await Model .when (search, (query , value ) => query .where (' search' , value))
193
205
```
194
206
207
+ ## ` wrappedBy `
208
+
209
+ <alert type =" success " >Available in version >= v1.14.0</alert >
210
+
211
+ - Arguments: ` (value) `
212
+ - Returns: ` self `
213
+
214
+ Change the ` wrap() ` data wrapper for this request.
215
+
216
+ ``` js
217
+ await Model .wrappedBy (' somewrapper' ).get ()
218
+ ```
219
+
220
+ ## ` nowrap `
221
+
222
+ <alert type =" success " >Available in version >= v1.14.0</alert >
223
+
224
+ - Returns: ` self `
225
+
226
+ Remove the ` wrap() ` data wrapper for this request to return the raw response.
227
+
228
+ ``` js
229
+ await Model .nowrap ().get ()
230
+ ```
231
+
195
232
## ` custom `
233
+
196
234
- Arguments: ` (...args) `
197
235
- Returns: ` self `
198
236
@@ -201,38 +239,39 @@ Build custom endpoints.
201
239
<code-group >
202
240
<code-block Label =" Simple Query " active >
203
241
204
- ``` js
205
- await Post .custom (' posts/latest' )
206
- ```
242
+ ``` js
243
+ await Post .custom (' posts/latest' )
244
+ ```
207
245
208
246
</code-block >
209
247
<code-block Label =" Simple Request " >
210
248
211
- ``` http request
212
- GET /posts/latest
213
- ```
249
+ ``` http request
250
+ GET /posts/latest
251
+ ```
214
252
215
253
</code-block >
216
254
<code-block Label =" Complex Query " >
217
255
218
- ``` js
219
- const user = new User ({ id: 1 })
220
- const post = new Post ()
256
+ ``` js
257
+ const user = new User ({ id: 1 })
258
+ const post = new Post ()
221
259
222
- await Post .custom (user, post, ' latest' )
223
- ```
260
+ await Post .custom (user, post, ' latest' )
261
+ ```
224
262
225
263
</code-block >
226
264
<code-block Label =" Complex Request " >
227
265
228
- ``` http request
229
- GET /users/1/posts/latest
230
- ```
266
+ ``` http request
267
+ GET /users/1/posts/latest
268
+ ```
231
269
232
270
</code-block >
233
271
</code-group >
234
272
235
273
## ` config `
274
+
236
275
<alert type =" success " >Available in version >= v1.8.0</alert >
237
276
238
277
- Arguments: ` (config) `
@@ -243,12 +282,15 @@ Configuration of HTTP Instance.
243
282
``` js
244
283
await Model .config ({
245
284
method: ' PATCH' ,
246
- header: { /* ... */ },
285
+ header: {
286
+ /* ... */
287
+ },
247
288
data: { foo: ' bar' }
248
289
}).save ()
249
290
```
250
291
251
292
## ` get `
293
+
252
294
- Returns: ` Collection | { data: Collection } `
253
295
254
296
Execute the query and get all results.
@@ -260,6 +302,7 @@ await Model.get()
260
302
<alert type =" info " >` all ` is an alias of this method.</alert >
261
303
262
304
## ` first `
305
+
263
306
- Returns: ` Model | { data: Model } `
264
307
265
308
Execute the query and get the first result.
@@ -269,6 +312,7 @@ await Model.first()
269
312
```
270
313
271
314
## ` find `
315
+
272
316
- Arguments: ` (identifier) `
273
317
- Returns: ` Model | { data: Model } `
274
318
@@ -279,6 +323,7 @@ await Model.find(1)
279
323
```
280
324
281
325
## ` $get `
326
+
282
327
- Returns: ` Collection `
283
328
284
329
Execute the query and get all results.
@@ -293,6 +338,7 @@ They handle and unwrap responses within "data".</alert>
293
338
<alert type =" info " >` $all ` is an alias of this method.</alert >
294
339
295
340
## ` $first `
341
+
296
342
- Returns: ` Model `
297
343
298
344
Execute the query and get the first result.
@@ -301,10 +347,11 @@ Execute the query and get the first result.
301
347
await Model .$first ()
302
348
```
303
349
304
- <alert type =" info " >These ` $ ` -prefixed convenience methods always return the requested content.
350
+ <alert type =" info " >These ` $ ` -prefixed convenience methods always return the requested content.
305
351
They handle and unwrap responses within "data".</alert >
306
352
307
353
## ` $find `
354
+
308
355
- Arguments: ` (identifier) `
309
356
- Returns: ` Model `
310
357
@@ -314,5 +361,5 @@ Find a model by its primary key.
314
361
await Model .$find (1 )
315
362
```
316
363
317
- <alert type =" info " >These ` $ ` -prefixed convenience methods always return the requested content.
364
+ <alert type =" info " >These ` $ ` -prefixed convenience methods always return the requested content.
318
365
They handle and unwrap responses within "data".</alert >
0 commit comments