new ModelInstance(data, options)
This would be the constructor for the generated models.
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
data |
Object |
the model instance data |
||||||
options |
Object |
optional creation options
|
Extends
Members
-
static ModelInstance.modelName
-
The name of the model.
-
static ModelInstance.schema
-
Schema the schema of this model.
-
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 true
if we have errors,false
otherwise. -
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
toObject
but applied whenJSON.stringify
is calledName Type Description options
Object 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 options
Object Name Type Description transform
function a transform function to apply to the resulting document before returning.
virtuals
Boolean apply virtual getters. Default:
false
minimize
Boolean remove empty objects. Default:
true
dateToISO
Boolean convert dates to string in ISO format using
Date.toISOString()
. Default:false
Returns:
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()
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
.