0

I'm constructing a Parse.com query inside a Parse query on the browser in a Parse/backbone app.

I have a two stage query (and want the intermediate results) so I construct the second query in a when clause from the first query's fetch:

// changeJob is a backbone event handler triggered from global app state
changeJob: function() {

  var taskQuery = new Parse.Query(Task);
  taskQuery.equalTo("publicJob", theAppState.get("publicJob"));
  taskQuery.equalTo("status", "accepted");

  taskQuery.limit(20);

  this.tasks.query = taskQuery;
  var self = this;
  this.tasks.fetch().then(function(foundTasks){

    console.log("got " + foundTasks.length + " tasks");
    var responsesQuery = new Parse.Query(StepResponse);
    responsesQuery.containedIn("task", foundTasks);    /// Stack blows here
    responsesQuery.include("task");
    responsesQuery.include("task.taskLocation");
    responsesQuery.limit(1000);

    self.responses.query = responsesQuery;

    console.log("fetch the step responses");
    self.responses.fetch();
  });

My collections are model objects are declared with global scope:

var StepResponse = Parse.Collection.extend("StepResponse", {
    });

// StepResponse Collection
var StepResponseCollection = Parse.Collection.extend({
  model: StepResponse,
    });

var Task = Parse.Object.extend("Task", {
    });

// Task Collection
var TaskCollection = Parse.Collection.extend({
  model: Task,
});

When I try to restrict the inner query based on using the array from the first query, I get a Maximum Stack size exceeded error.

I've seen a few people discuss this on SO but I don't think that they are duplicates - I don't have any bi directional links between these two classes and the stack blows when I'm setting up the query, before I execute it of try to save any objects.

Rog
  • 17,070
  • 9
  • 50
  • 73
  • 1
    Notice that you shouldn't asynchronously "export" `self.responses.query = responsesQuery;`, but rather **`return`** promises from all you asynchronous functions (both `changeJob` and the `then()` callback). – Bergi Mar 03 '15 at 15:05
  • Isn't that the way you add the query in the Parse/Backbone model? I thought you need that so that self.responses.fetch() populates the Collection. – Rog Mar 03 '15 at 15:33
  • 1
    Oops, I don't know Parse/Backbone that well, I thought you were trying to [popoluate a data variable asynchronously](http://stackoverflow.com/q/23667086/1048572). Still you should `return` the `.fetch()` promises, though. – Bergi Mar 03 '15 at 15:37

0 Answers0