Permalink
Browse files

Modified the constructor for superModel to preserver the current coll…

…ection.
  • Loading branch information...
1 parent 89b73e0 commit 11529591a68cc1282013bf34c97c00cacc2620a6 @rlgnak rlgnak committed with Feb 12, 2013
Showing with 12 additions and 2 deletions.
  1. +5 −1 supermodel.js
  2. +1 −1 supermodel.min.js
  3. +6 −0 test/model.js
View
@@ -443,7 +443,11 @@
// Add the model to `all` for each constructor in its prototype chain.
var ctor = this.constructor;
- do { ctor.all().add(this); } while (ctor = ctor.parent);
+ do {
+ var collection = this.collection;
+ ctor.all().add(this);
+ this.collection = collection;
+ } while (ctor = ctor.parent);
// Trigger 'initialize' for listening associations.
this.trigger('initialize', this);
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -66,6 +66,12 @@
ok(Model.create({cid: model.cid}) !== model);
});
+ test('Model creation doesn\'t set the model collection as the all collection.', function() {
+ var Model = Supermodel.Model.extend();
+ var model = Model.create();
+ ok(model.collection === undefined);
+ });
+
test('Use cidAttribute to identify attributes.', function() {
var Model = Supermodel.Model.extend({cidAttribute: '_cid'});
var model = Model.create();

0 comments on commit 1152959

Please sign in to comment.