Class: ModelInstance

ModelInstance

new ModelInstance(data)

Constructs a new model instance and for models with a default constructor, applies the data in object passed to the instance.

Parameters:
Name Type Description
data Object

Methods

<static> applyData(mdlInst, data)

Applies the data passed in data to the model instance mdlInst.

Parameters:
Name Type Description
mdlInst ModelInstance
data Object

<static> count(filter, options, callback)

Performs a count of the objects matching the filter in the data store.

Parameters:
Name Type Argument Description
filter Object
options Object <optional>
Properties
Name Type Description
sort string | Array.<string>
limit number
skip number
callback function

<static> create(data, callback)

Creates a new ModelInstance with the passed data and then immediately attempts to save it to the data store.

Parameters:
Name Type Description
data Object
callback function

<static> find(filter, options, callback)

Perform a filter based search to locate specific model instances.

Parameters:
Name Type Argument Description
filter Object
options Object <optional>
Properties
Name Type Description
sort string | Array.<string>
limit number
skip number
callback function

<static> fromData(data)

Creates a new instance of this Model from the data passed.

Parameters:
Name Type Description
data Object
Returns:

ModelInstance

<static> getById(id, callback)

Retrieves a specific model instance from the data store by ID.

Parameters:
Name Type Description
id string
callback function

<static> namePath() → {string}

Returns the full name of the model, including namespace.

Returns:
Type
string

<static> post(event, fn)

Specify a function to be invoked following a particular event on this ModelInstance.

Parameters:
Name Type Description
event "validate" | "save" | "load"
fn function

<static> pre(event, handler)

Specify a handler to be invoked prior to a particular event for this ModelInstance.

Parameters:
Name Type Description
event "validate" | "save" | "load"
handler function

<static> ref(id) → {ModelInstance}

Creates an unloaded model instance referencing a data store item by id.

Parameters:
Name Type Description
id string
Returns:
Type
ModelInstance

<static> refByKey(key) → {ModelInstance}

Creates an unloaded model instance referencing a data store item by key.

Parameters:
Name Type Description
key string
Returns:
Type
ModelInstance

id() → {string}

Returns the ID of this model instance.

Returns:
Type
string

load(paths, callback)

Loads this object, or sub-objects from this object from the data store. This function can be called while a model instance is already loaded to reload the model instance, or to load specific sub-model-instances.

Parameters:
Name Type Argument Description
paths string <optional>
<repeatable>

Paths to sub-model-instances to load.

callback function

loaded() → {boolean}

Returns whether this model instance is loaded or not.

Returns:
Type
boolean

remove(callback)

Removes this model instance from the data store.

Parameters:
Name Type Description
callback function

save(callback)

Saves this model instance to the data store.

Parameters:
Name Type Description
callback function

toJSON() → {Object}

Returns a JSON serialized version of this model instance.

Returns:
Type
Object