Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Re-arranged update logic inside of DS.Store.create. Model arrays are …

…now updated after the store's model array has been updated. Fix for #21.
  • Loading branch information...
commit 8fcaa03bdebd2f939545cd2cb3ad5d34cfa482a7 1 parent b956941
Gordon L. Hempton authored January 03, 2012
5  packages/ember-data/lib/system/store.js
@@ -153,11 +153,12 @@ DS.Store = SC.Object.extend({
153 153
     var models = get(this, 'models');
154 154
 
155 155
     var clientId = this.pushHash(hash, id, type);
156  
-    this.updateModelArrays(type, clientId, hash);
157 156
 
158 157
     set(model, 'clientId', clientId);
159 158
 
160  
-    get(this, 'models')[clientId] = model;
  159
+    models[clientId] = model;
  160
+    
  161
+    this.updateModelArrays(type, clientId, hash);
161 162
 
162 163
     return model;
163 164
   },
2  packages/ember-data/tests/model_array_test.js
@@ -148,8 +148,6 @@ test("a model array that backs a collection view functions properly", function()
148 148
   store.load(Person, 5, { name: "Other Katz" });
149 149
   
150 150
   var container = Ember.CollectionView.create({
151  
-    classNameBindings: ['name'],
152  
-    name: 'foo',
153 151
     content: store.findAll(Person)
154 152
   });
155 153
 
34  packages/ember-data/tests/store_test.js
@@ -325,6 +325,40 @@ test("if an id is supplied in the initial data hash, it can be looked up using `
325 325
   strictEqual(person, again, "the store returns the loaded object");
326 326
 });
327 327
 
  328
+test("models inside a collection view should have their ids updated", function() {
  329
+  var Person = DS.Model.extend({
  330
+    id: DS.attr("integer")
  331
+  });
  332
+  
  333
+  idCounter = 1;
  334
+  var adapter = DS.Adapter.create({
  335
+    create: function(store, type, model) {
  336
+      store.didCreateModel(model, {name: model.get('name'), id: idCounter++});
  337
+    }
  338
+  });
  339
+
  340
+  var store = DS.Store.create({
  341
+    adapter: adapter
  342
+  });
  343
+  
  344
+  var container = Ember.CollectionView.create({
  345
+    content: store.findAll(Person)
  346
+  });
  347
+
  348
+  Ember.run(function() {
  349
+    container.appendTo('#qunit-fixture');
  350
+  });
  351
+  
  352
+  console.log(store.create(Person, { name: "Newt Gingrich" }));
  353
+  console.log(store.create(Person, { name: "Ron Paul" }));
  354
+  store.commit();
  355
+  
  356
+  container.content.forEach(function(person, index) {
  357
+    console.log(person);
  358
+    equal(person.get('id'), index + 1, "The model's id should be correctly.");
  359
+  });
  360
+});
  361
+
328 362
 module("DS.State - Lifecycle Callbacks");
329 363
 
330 364
 test("a model receives a didLoad callback when it has finished loading", function() {

0 notes on commit 8fcaa03

Please sign in to comment.
Something went wrong with that request. Please try again.