From 57f1588dea9c12ff869baa9222f202ebb7b6a72f Mon Sep 17 00:00:00 2001 From: Scott Erickson <sderickson@gmail.com> Date: Sat, 8 Mar 2014 14:34:25 -0800 Subject: [PATCH] Fixed another bug related to the race condition fix. --- app/models/SuperModel.coffee | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/SuperModel.coffee b/app/models/SuperModel.coffee index 36a7fab72..9ce14c75d 100644 --- a/app/models/SuperModel.coffee +++ b/app/models/SuperModel.coffee @@ -2,6 +2,7 @@ class SuperModel constructor: -> @models = {} @collections = {} + @schemas = {} _.extend(@, Backbone.Events) populateModel: (model) -> @@ -25,8 +26,11 @@ class SuperModel @removeEventsFromModel(model) modelLoaded: (model) -> + model.loadSchema() schema = model.schema() - return schema.once('sync', => @modelLoaded(model)) unless schema.loaded + unless schema.loaded + @schemas[schema.urlRoot] = schema + return schema.once('sync', => @modelLoaded(model)) refs = model.getReferencedModels(model.attributes, schema.attributes, '/', @shouldLoadProjection) refs = [] unless @mustPopulate is model or @shouldPopulate(model) # console.log 'Loaded', model.get('name') @@ -96,9 +100,12 @@ class SuperModel total = 0 loaded = 0 - for key, model of @models + for model in _.values @models total += 1 loaded += 1 if model.loaded + for schema in _.values @schemas + total += 1 + loaded += 1 if schema.loaded return 1.0 unless total return loaded / total