@@ -6,6 +6,7 @@ category: API
66---
77
88## ` include `
9+
910- Arguments: ` (...args) `
1011- Returns: ` self `
1112
@@ -26,6 +27,7 @@ await Model.include(['user', 'category'])
2627<alert type =" info " >` with ` is an alias of this method.</alert >
2728
2829## ` append `
30+
2931- Arguments: ` (...args) `
3032- Returns: ` self `
3133
@@ -44,17 +46,20 @@ await Model.append(['likes', 'shares'])
4446```
4547
4648## ` select `
49+
4750- Arguments: ` (...fields) `
4851- Returns: ` self `
4952
5053Set the columns to be selected.
5154
5255#### Single entity
56+
5357``` js
5458await Model .select ([' title' , ' content' ])
5559```
5660
5761#### Related entities
62+
5863``` js
5964await Post .select ({
6065 posts: [' title' , ' content' ],
@@ -63,6 +68,7 @@ await Post.select({
6368```
6469
6570## ` where `
71+
6672- Arguments: ` (field, value) `
6773- Returns: ` self `
6874
@@ -89,6 +95,7 @@ await Model.where({ user: { status: 'active' } })
8995```
9096
9197## ` whereIn `
98+
9299- Arguments: ` (field, array) `
93100- Returns: ` self `
94101
@@ -115,24 +122,26 @@ await Model.where({ user: { id: [1, 2, 3] } })
115122```
116123
117124## ` orderBy `
125+
118126- Arguments: ` (...args) `
119127- Returns: ` self `
120128
121129Add an "order by" clause to the query.
122130
123131``` js
124- await Model .orderBy (' -created_at' , ' category_id' )
132+ await Model .orderBy (' -created_at' , ' category_id' )
125133```
126134
127135#### Array
128136
129137<alert type =" success " >Available in version >= v1.8.0</alert >
130138
131139``` js
132- await Model .orderBy ([' -created_at' , ' category_id' ])
140+ await Model .orderBy ([' -created_at' , ' category_id' ])
133141```
134142
135143## ` page `
144+
136145- Arguments: ` (value) `
137146- Returns: ` self `
138147
@@ -143,6 +152,7 @@ await Model.page(1)
143152```
144153
145154## ` limit `
155+
146156- Arguments: ` (value) `
147157- Returns: ` self `
148158
@@ -153,6 +163,7 @@ await Model.limit(20)
153163```
154164
155165## ` params `
166+
156167- Arguments: ` (payload) `
157168- Returns: ` self `
158169
@@ -161,24 +172,25 @@ Add custom parameters to the query.
161172<code-group >
162173 <code-block Label =" Query " active >
163174
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+ ```
170181
171182 </code-block >
172183 <code-block Label =" Request " >
173184
174- ``` http request
175- GET /resource?foo=bar&baz=true
176- ```
185+ ``` http request
186+ GET /resource?foo=bar&baz=true
187+ ```
177188
178189 </code-block >
179190</code-group >
180191
181192## ` when `
193+
182194<alert type =" success " >Available in version >= v1.10.0</alert >
183195
184196- Arguments: ` (value, callback) `
@@ -192,7 +204,33 @@ const search = 'foo'
192204await Model .when (search, (query , value ) => query .where (' search' , value))
193205```
194206
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+
195232## ` custom `
233+
196234- Arguments: ` (...args) `
197235- Returns: ` self `
198236
@@ -201,38 +239,39 @@ Build custom endpoints.
201239<code-group >
202240 <code-block Label =" Simple Query " active >
203241
204- ``` js
205- await Post .custom (' posts/latest' )
206- ```
242+ ``` js
243+ await Post .custom (' posts/latest' )
244+ ```
207245
208246 </code-block >
209247 <code-block Label =" Simple Request " >
210248
211- ``` http request
212- GET /posts/latest
213- ```
249+ ``` http request
250+ GET /posts/latest
251+ ```
214252
215253 </code-block >
216254 <code-block Label =" Complex Query " >
217255
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 ()
221259
222- await Post .custom (user, post, ' latest' )
223- ```
260+ await Post .custom (user, post, ' latest' )
261+ ```
224262
225263 </code-block >
226264 <code-block Label =" Complex Request " >
227265
228- ``` http request
229- GET /users/1/posts/latest
230- ```
266+ ``` http request
267+ GET /users/1/posts/latest
268+ ```
231269
232270 </code-block >
233271</code-group >
234272
235273## ` config `
274+
236275<alert type =" success " >Available in version >= v1.8.0</alert >
237276
238277- Arguments: ` (config) `
@@ -243,12 +282,15 @@ Configuration of HTTP Instance.
243282``` js
244283await Model .config ({
245284 method: ' PATCH' ,
246- header: { /* ... */ },
285+ header: {
286+ /* ... */
287+ },
247288 data: { foo: ' bar' }
248289}).save ()
249290```
250291
251292## ` get `
293+
252294- Returns: ` Collection | { data: Collection } `
253295
254296Execute the query and get all results.
@@ -260,6 +302,7 @@ await Model.get()
260302<alert type =" info " >` all ` is an alias of this method.</alert >
261303
262304## ` first `
305+
263306- Returns: ` Model | { data: Model } `
264307
265308Execute the query and get the first result.
@@ -269,6 +312,7 @@ await Model.first()
269312```
270313
271314## ` find `
315+
272316- Arguments: ` (identifier) `
273317- Returns: ` Model | { data: Model } `
274318
@@ -279,6 +323,7 @@ await Model.find(1)
279323```
280324
281325## ` $get `
326+
282327- Returns: ` Collection `
283328
284329Execute the query and get all results.
@@ -293,6 +338,7 @@ They handle and unwrap responses within "data".</alert>
293338<alert type =" info " >` $all ` is an alias of this method.</alert >
294339
295340## ` $first `
341+
296342- Returns: ` Model `
297343
298344Execute the query and get the first result.
@@ -301,10 +347,11 @@ Execute the query and get the first result.
301347await Model .$first ()
302348```
303349
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.
305351They handle and unwrap responses within "data".</alert >
306352
307353## ` $find `
354+
308355- Arguments: ` (identifier) `
309356- Returns: ` Model `
310357
@@ -314,5 +361,5 @@ Find a model by its primary key.
314361await Model .$find (1 )
315362```
316363
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.
318365They handle and unwrap responses within "data".</alert >
0 commit comments