Clients do not need to create Models manually.
| Name | Type | Description |
|---|---|---|
values |
||
options |
||
schema |
||
name |
Returns:
| Type | Description |
|---|---|
| Model |
Members
-
The name the name of the model. This is both a static and instance property.
Example
var schema = plaster.schema({ name: String });
var Cat = plaster.model('Cat', schema);
var kitty = new Cat({ name: 'Zildjian' });
console.log(Cat.modelName); // 'Cat'
console.log(kitty.modelName); // 'Cat' -
Schema the schema of this model. This is both a static and instance property.
Methods
-
Clear the model data.
-
Clears all the errors.
-
Gets the errors object.
-
Checks whether we have any errors.
Returns:
Type Description Boolean trueif we have errors,falseotherwise. -
Helper for
console.log. Just invokes defaulttoObject. -
Sets data on the model based on the schema.
Accepts a key of property and value for the property, or object representing the data for document.Example
user.set('fistName', 'Joe');
user.set({ lastName: 'Smith'); -
Similar as
toObjectbut applied whenJSON.stringifyis calledName Type Description optionsObject Same options as
toObject.Returns:
Type Description Object Plain javascript object representation of document. -
Converts this document into a plain javascript object.
Name Type Description optionsObject Name Type Description transformfunction a transform function to apply to the resulting document before returning.
virtualsBoolean apply virtual getters. Default:
falseminimizeBoolean remove empty objects. Default:
truedateToISOBoolean convert dates to string in ISO format using
Date.toISOString(). Default:falseReturns:
Type Description Object Plain javascript object representation of document. Examples
var userSchema = plaster.schema({ name: String });
var User = plaster.model('User', userSchema);
var user = new User({name: 'Joe Smith'});
console.log(user); // automatically invokes toObject()Example with transform option.
var xform = function (doc, ret, options) {
ret.name = ret.name.toUpperCase();
return ret;
};
console.dir(user.toObject({transform: xform}); // { name: 'JOE SMITH' } -
Helper for
console.log. Alias forinspect.