Model Utils

This class provides utility functions for models and collections, including: an instanceof wrappers, factory methods, and getters for constructors based on the name. The ModelUtils class is initialized in the app initialization process, and is attached to the app object.

getCollection ModelUtils.getCollection(path, [models], [options], [callback])

Factory method for collections. Given the path of a collection, this function will return an instance of that collection. This will also add the models to that collection, and set any options to the collection. callback allows the method to be called asynchronously.

path The path to the collection. For example: my_collection, would return an instance of a collection stored in app/collections/my_collection.js

models optional An array of models to store in the collection.

options optional Options for the collection constructor.

callback optional Callback function to be invoked once the instance is created. If a callback is not passed in, this will return the instance instead.

getModel ModelUtils.getModel(path, [attributes], [options], [callback])

Factory method for models. Given the models path this will return an instance of that model. Sets the given attributes and options on the model.

attributes optional The attributes for the constructor.

options optional The options to set in a constructor method.

callback optional Allows the constructor to be called with a callback method instead.

isCollection ModelUtils.isCollection(obj)

Returns a boolean if the obj is an instance of a Collection.

isModel ModelUtils.isModel(obj)

Returns a boolean if the obj is an instance of a Model.

underscorize ModelUtils.underscorize(name)

Return a snake case version of the model or collection name. For example: MyModel would return my_model.