Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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.

share|improve this question
    
What have you tried, and what issues have you encountered? – Harris Weinstein yesterday
    
Edited my original post. – Thomas Vansteelandt 14 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.