title | description | position | category |
---|---|---|---|
Model Options |
Model Options. |
6 |
API |
It's recommended to define the global options in your Base Model, in order to abstract configuration from your models.
- Returns:
HTTP Client Instance
Instance of the HTTP client which is used to make requests.
See Installation
- Returns:
string
Base URL which is used and prepended to make requests.
See Configuration
baseURL() {
return 'http://my-api.com'
}
- Arguments:
(config)
- Returns:
HTTP Client Request
Request method which is used to make requests.
See Configuration
request(config) {
return this.$http.request(config)
}
- Returns:
object
This method can be overridden in the model to customize the name of the query parameters.
See Configuration
parameterNames() {
return {
include: 'include',
filter: 'filter',
sort: 'sort',
fields: 'fields',
append: 'append',
page: 'page',
limit: 'limit'
}
}
- Default:
include
- Returns:
string
- Default:
filter
- Returns:
string
- Default:
sort
- Returns:
string
- Default:
fields
- Returns:
string
- Default:
append
- Returns:
string
- Default:
page
- Returns:
string
- Default:
limit
- Returns:
string
These are model-related options.
- Returns:
string
Resource route of the model which is used to build the query.
See Configuration
resource() {
return 'resource'
}
- Default:
id
- Returns:
string
Primary key of the model which is used to build the query.
See Configuration
primaryKey() {
return 'id'
}
- Returns:
object
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 model instance.
See Configuration
relations() {
return {
comments: Comment
}
}
- Arguments:
(model)
- Returns:
Model
This method can be used to lazy load relationships of a model and apply model instances to them.
It must receive a model instance as argument.
See Configuration
comments() {
return this.hasMany(Comment)
}