Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions docs/content/en/api/model-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ category: API

## Global Options

It's recommended to define the global options in your [Base Model](/configuration#creating-a-base-model),
It's recommended to define the global options in your [Base Model](/configuration#creating-a-base-model),
in order to abstract configuration from your models.

### `$http`

- Returns: `HTTP Client Instance`

Instance of the HTTP client which is used to make requests.

See [Installation](/installation)

### `baseURL`

- Returns: `string`

Base URL which is used and prepended to make requests.
Expand All @@ -31,6 +33,7 @@ baseURL() {
```

### `request`

- Arguments: `(config)`
- Returns: `HTTP Client Request`

Expand All @@ -45,6 +48,7 @@ request(config) {
```

### `parameterNames`

- Returns: `object`

This method can be overridden in the model to customize the name of the query parameters.
Expand All @@ -66,34 +70,42 @@ parameterNames() {
```

#### `include`

- Default: `include`
- Returns: `string`

#### `filter`

- Default: `filter`
- Returns: `string`

#### `sort`

- Default: `sort`
- Returns: `string`

#### `fields`

- Default: `fields`
- Returns: `string`

#### `append`

- Default: `append`
- Returns: `string`

#### `page`

- Default: `page`
- Returns: `string`

#### `limit`

- Default: `limit`
- Returns: `string`

### `formData`

- Returns: `object`

This method can be overridden in the model to configure `object-to-formdata`.
Expand All @@ -112,6 +124,7 @@ formData() {
```

### `stringifyOptions`

- Default: `{ encode: false, arrayFormat: 'comma' }`
- Returns: `object`

Expand All @@ -133,6 +146,7 @@ stringifyOptions() {
These are model-related options.

### `resource`

- Returns: `string`

Resource route of the model which is used to build the query.
Expand All @@ -146,6 +160,7 @@ resource() {
```

### `primaryKey`

- Default: `id`
- Returns: `string`

Expand All @@ -159,10 +174,26 @@ primaryKey() {
}
```

### `wrap`

- Default: `null`
- Returns: `string`

The "data" wrapper that should be checked when retrieving models.

See [Configuration](/configuration#changing-the-wrapper)

```js
wrap() {
return 'data'
}
```

### `relations`

- Returns: `object`

This method can be implemented in the model to apply model instances to eager loaded relationships.
This method can be implemented in the model to apply model instances to eager loaded relationships.
It works for collections too.

It must return an object, which the key is the property of the relationship, and the value is the
Expand All @@ -179,6 +210,7 @@ relations() {
```

### `hasMany`

- Arguments: `(model)`
- Returns: `Model`

Expand Down
Loading
Loading