I'm using Parse.com within an angular project. I'm trying to figure out how to initialize a User object and fetch relational data within that function.
var app = angular.module('f', []);
app.factory('User', ['$q', function($q){
var User = Parse.Object.extend('_User', {
initialize: function(attrs, options){
// Fetch some other related data to this user
}, {
}
);
return User;
}]);
Any help is greatly appreciated!
EDIT: I've tried this inside initialize:
var UserData = Parse.Object.extend('UserData');
var thisUser = this;
var qry = new Parse.Query(UserData);
qry.equalTo("user", this.objectId);
qry.find({
success: function(results){
thisUser.userdata = results;
}
});
But ended up with an infinite loop. Is it even possible to get data through a promise inside an initialize function? Because the init happens instantly but the relational data takes some time to fetch.