I have a model which describes an organization, and a sub-collection which describes permissions on the organization.
In my view I need to fetch data from both the models before rendering. When I bind my view rendering method to one event (e.g model.change or subcollection.sync), there are times which my screen displays before my models are populated, thus producing an error.
Here is the relevant part of my code:
this.model = new OrgModel({id: id});
this.model.permissions = new PermissionsCollection({org: id});
this.model.permissions.on("sync", this.render); // SOMETIMES GETS CALLED BEFORE model:sync GETS CALLED
this.model.permissions.fetch({error: Utils.apiError});
this.model.fetch({error: Utils.apiError});
I am unsure which event to call "render" - because there are times which each request comes back first.
Is there a way to bind the "sync" events together so that when a model.fetch is called, it in turn calls the subcollection.fetch, and does not pass back the "sync" event until the subcollection:sync is called?