Class: ModelInstance

Cassandra.Model.ModelInstance

Creates a new ModelInstance object based on your model's schema, this class extends the model.Factory class object, which is what's returned everytime you instantiate a new Model(ColumnFamily)

Constructor

new ModelInstance(dataObject, model)

Parameters:
Name Type Description
dataObject object an object containing column:values that will initialize the instance
model object the model this instance is based off of
Source:

Methods

_prepareObject()

This is called at instantiation of each new ModelInstance and will store the qualified data in a secret place. This data store and the instance's enumerable properties(columns) is updated on MOST successful actions except for when deleting the entire object from the table, then the data is left intact. restore() will restore the instances column values to the values in the data store;
Source:

delete(deleteObject, callback)

Delete columns or entire rows from a model instance. When deleting a deleteObject of columns, the projected columns will be set to null on the instance and the data store. This is essentially the same as setting values to null and using save. Currently, this method doesn't support using timestamps but it will soon
Parameters:
Name Type Description
deleteObject array an array of columns to delete [optional]
callback function receives err
Source:
To Do:
  • support @usingTimestamp/delete options

restore()

Instanced Models have the ability to rollback failed writes, for example, if you attempt to "model.save(...)" and this produces an errror, in your callback you can then determine if you wish to restore the object data model back to the values it has saved from the last sync with your database or continue on with the local data
Source:
Example

Restore last data synced

//user schema: { name: 'text' }, { primaryKeys: [ 'name' ] }
user = new TestModel({name: 'foo'});
//we should not be able to update a primary key
user.name = 'bar';
user.save((err) => {
  if (err) {
    //user.name == 'bar'
    user.restore();
    //user.name == 'foo'
  }
});

save(callback)

Save values altered since instantiation
Parameters:
Name Type Description
callback function receives err
Source:

sync(callback)

Save the current instance's data model to the table this will create a new row if you have altered a primary key or are saving an object for the first time with save()
Parameters:
Name Type Description
callback function receives err
Source: