/**
* Surveys.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs        :: http://sailsjs.org/#!documentation/models
*/

module.exports = {
    connection: 'someMongodbServer',
    attributes: {
        userId : {type: 'string', required: true },
        name: { type: 'string', required: true },
        description: 'string',
        location: 'string',
        shortUrl: 'string',
        qrCode : 'string',
        questions: { collection: 'questions' },
        responses : { collection : 'responses'}
    },
    // Lifecycle Callbacks
    beforeCreate: function (values, cb) {
        var bitlyApi = require("node-bitlyapi");
        var bitly = new bitlyApi();
        bitly.setAccessToken("2bf203037bb7b0c89d1eb6768b9646551d25d49f");
        bitly.shortenLink("http://xignal.co/id/" + values.id, function (err, results) {
            values.shortUrl = JSON.parse(results).data.url;
            values.qrCode = "https://chart.googleapis.com/chart?chs=150x150&amp;cht=qr&amp;chl=" + values.shortUrl;
            cb();
        });
    }
};


@@ -613,14 +613,13 @@
     
-before
+after
 Crea
@@ -1065,24 +1065,185 @@
 s.shortUrl;%0A
+            Surveys.update(%7B id: values.id %7D, %7B shortUrl: values.shortUrl, qrCode: values.qrCode %7D)%0A                   .exec(function (err, updatedServers) %7B%7D);%0A
             

Fix surveys field update when created (using afterCreate now + update on the colection)