Jake T.
Jake T.

Reputation: 4378

Cloud code - Parse.Object initializer isn't working

I'm probably missing something stupid, but my initializer function for a custom parse class isn't working in cloud code. I have the following in my cloud code, and call the "createAStatisticTest" function from my client, which successfully creates and saves a new Statistics object, but doesn't update any of the data to 0. All of the data is (undefined). Can anyone point out what I'm doing wrong?

var Statistics = Parse.Object.extend("Statistics",
    { //instance methods
        initialize: function(attrs, options)
        {
            this.newUsers = 0;
            this.newBillableUsers = 0;
            this.firstCut = 0;
            this.additionalCuts = 0;
            this.numCuts = 0;
            this.totalBillableUsers = 0;
        }
    },
    {} //class methods
);

//Create a single statistics object to show that the parameters inside of the intialize function aren't being set properlly
Parse.Cloud.define("createAStatisticTest", function(request, status)
{
    var statistics = new Statistics();
    statistics.save().then
    (
        function( statistics )
        {
            status.success("Saved the statistic object");
        },
        function( error )
        {
            status.error("There was an error saving the object: " + error.message);
        }
    )
});

I based my implementation off of the js guide's Monster object example found here

Upvotes: 0

Views: 90

Answers (1)

eschanet
eschanet

Reputation: 1045

I had a similar problem a few weeks ago, where everything returned (undefined) suddenly. I solved it by changing the JavaScript SDK version back to version 1.4.2 - so it seems Parse has a bug in their latest SDK version.

Please have a look at this answer.

Upvotes: 1

Related Questions