new ExtendedBuilderApi()
Non-core builder extensions
Adds the following property modifiers:
* serialize
sets the encoder and decoder beaviour for an attribute, maps to BuilderApi#attrSerializer
- Source:
- module/extended/builder-ext.js, line 8
Methods
-
attrExpression(_name, _expr) → {BuilderApi}
-
Expression attributes are evaluated every time new data is fed to the model.
Parameters:
Name Type Description _name
string Attribute name
_expr
string Angular expression to evaluate
- Source:
- module/extended/builder-ext.js, line 100
Returns:
self
- Type
- BuilderApi
-
attrSerializer(_name, _serializer) → {BuilderApi}
-
Assigns a serializer to a given attribute.
A _serializer is: an object that defines both a
decode
and aencode
method a function that when called returns an object that matches the above description. * a string that represents an injectable that matches any of the above descriptions.Parameters:
Name Type Description _name
string Attribute name
_serializer
string | object | function The serializer
- Source:
- module/extended/builder-ext.js, line 78
Returns:
self
- Type
- BuilderApi
-
setPrimaryKey(_key) → {BuilderApi}
-
Changes the model's primary key.
Primary keys are passed to scope's url methods to generate urls. The default primary key is 'id'.
ATTENTION Primary keys are extracted from raw data, so _key must use raw api naming.
Parameters:
Name Type Description _key
string | function New primary key.
- Source:
- module/extended/builder-ext.js, line 60
Returns:
self
- Type
- BuilderApi
-
setUrlPrefix(_prefix) → {BuilderApi}
-
Sets an url prefix to be added to every url generated by the model.
This applies even to objects generated by the
$single
method.This method is intended to be used in a base model mixin so everymodel that extends from it gets the same url prefix.
Usage:
var BaseModel = restmod.mixin(function() { this.setUrlPrefix('/api'); }) var bike = restmod.model('/bikes', BaseModel).$build({ id: 1 }); console.log(bike.$url()) // outputs '/api/bikes/1'
Parameters:
Name Type Description _prefix
string url portion
- Source:
- module/extended/builder-ext.js, line 44
Returns:
self
- Type
- BuilderApi