Upgrading from 1.0 to 2.0

Upgrage to v2 is recommended as it solidifies concepts introduced in v1.
In terms of new features, it includes new Model.exists, Instance.populate , Mode.buildRefDocKey methods or new EMBEDDED Model association relation type. Numerous new options to already existing methods have been added.
Also note that in the time of v2 release, v2 includes numerous bugfixes which have not been backported to v1.
For full list of changes, please see the CHANGELOG

The following is brief list of breaking changes:

Model's get methods:

Behavior of Model.getById & Model.getBy[RefDocIndex] methods has been changed so that in case of storage key not found error, they return fulfilled promise with null value instead of rejected promise with a StorageError. Additional Model.getByIdOrFail & Model.getBy[RefDocIndex]OrFail methods has been added. These methods will return rejected promise with a StorageError when storage key not found error occurs.

Behavior of the Model.getMulti method has been changed in terms of what it fulfills with. Also the method returns always resolved promise. Prior v2, the method may return rejected promise with StorageMultiError.

RefDoc index names:

See the following example:


    var User = couchbase.define('User', {
        type: DataTypes.HASH_TABLE,
        schema: {
            username: {
                type: DataTypes.STRING
            }
        }
    }, {
        indexes: {
            refDocs: {
                /**
                 * You are no longer supposed to define refDoc indexes with hardcoded `getBy` method name prefix
                 * Prior `v2` the index definition would look like:
                 *     getByUsername: {keys: ['username']}
                 * Since `v2` "getBy" method prefix is added automatically to method name
                 * and so the index definition becomes:
                 */
                username: {keys: ['username']}
            }
        }
    })

Model.buildKey method signature:

The method signature has been changed so that current (v1):


var key = Model.buildKey('uniqueid', true);

becomes (v2):


var key = Model.buildKey('uniqueid', {parse: true});

Model.build method behavior:

Defined Model's schema default values are always applied to builded model instance. Prior v2, default values are applied only when sanitize boolean option is set (defaults to false)

Also, since v2, the method does not clone data values passed to it.

ModelInstance.update && ModelInstance.destroy behavior:

Since v2, by default, the methods will return rejected promise with an InstanceError when you make an attemt to update/destroy a model instance object with no cas value set (this can be overcame by the force option)

ModelInstance.cloneData

The method has been made part of private API and so it's no longer accessible throught cloneData method name

Hooks

support for callback based hook listeners has been removed. All async hook listeners are expected to return a Promise

comments powered by Disqus