Instances

Saving a new Model instance to the bucket

Model.create(data, [options])

    return User.create({
        username: 'happiecat',
        email: 'bla@bla.com'
    }).then(function(user) {
        //
    });

or

Model.build(data, [options]) => <Instance>

Which builds a new Model.Instance object with provided data & options

and then

Instance.save([options]) => {Promise<Instance>}

Which performs insert or update (=replace) operation on the instance

    const happie = User.build({
        username: 'happiecat',
        email: 'bla@bla.com'
    });

    return happie.save().then(function(happie) {
        console.log(happie.username); // $ > happiecat

        console.log(happie.getData()); // $ > {
                                       //          _id     : '000a2644-a151-4771-98ef-132134e1606e',
                                       //          _type   : 'User',
                                       //          username: 'happiecat',
                                       //          email   : 'bla@bla.com',
                                       //     }

        console.log(happie.getData('email')); // $ > bla@bla.com
    });

See Model API and Instance API for more information.

comments powered by Disqus