Generic model
var BauplanModel = require("bauplan.model");
or as part of the Bauplan bundle
var Bauplan = require("bauplan");
var BauplanModel = Bauplan.Model;
Create and instantiate a new model class
var FooModel = Bauplan.Model.extend({});
var fooinstance = new FooModel();
Create a model that requires authentication
var AuthenticatedFooModel = Bauplan.Model.extend({
_model: "authfoo",
authenticated: true
});
Set a model’s endpoint URL
var RestFooModel = Bauplan.Model.extend({
_model: "restfoo",
url: "/foo"
});
Pass properties to a model
var PropsFooModel = Bauplan.Model.extend({
_model: "propsfoo",
properties: {
foo: {
type: "integer",
exactLength: 3,
required: true
}
}
});
Listens to Events
Returns
BauplanModel
- Type
- constructor
Extends
- Thorax.Model
Requires
- lodash
- thorax
- bauplan.authentication
- Source:
Methods
(static) clear(args)
Clears the attributes of an instance and any corresponding instance in the memoized register enabling atrributes to be loaded from the server again if necessary
Overrides Thorax.Model.prototype.clear
Parameters
Name | Type | Description |
---|---|---|
args |
object |
- Source:
(static) destroy(args)
Destroys an instance and any corresponding instance in the memoized register
Overrides Thorax.Model.prototype.destroy
Parameters
Name | Type | Description |
---|---|---|
args |
object |
- Source:
(static) extend(optionsopt) → {constructor}
Parameters
Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object |
<optional> |
Constructor options Properties
|
- Source:
Returns
Model
- Type
- constructor
(static) fetch()
Overrides Thorax.Model.prototype.fetch
Prevented from being called if:
- this.nofetch
- authentication is required
- Source:
(static) getAttributes() → {object}
Returns instance’s attributes based on whitelist provided by model’s schema properties
- Source:
Returns
Whitelisted attributes
- Type
- object
(static) unmemoize(method, args)
Generic helper function for syncing instances and the memoization register
Parameters
Name | Type | Description |
---|---|---|
method |
string | |
args |
object |
- Source:
(inner) initialize(attrs, options)
Passes values and options to the constructor when creating a new instance
Creates attribute whitelist on first initialization and fetches unstance values if necesary
Parameters
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
attrs |
object | |||
options |
object | |||
options.fetch |
boolean |
<optional> |
false | Whether to fetch instance values from endpoint |
- Source: