Skip to content

Commit

Permalink
Don't make me have to manually add a model to the collection if it ha…
Browse files Browse the repository at this point in the history
…s an id attribute.
  • Loading branch information
benpickles committed Feb 11, 2011
1 parent f4c4a0a commit c8755af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/model_instance_methods.js
Expand Up @@ -35,10 +35,10 @@ Model.InstanceMethods = {

// Automatically manage adding and removing from the model's Collection.
var manageCollection = function() {
if (method === "create") {
self.constructor.add(self);
} else if (method === "destroy") {
if (method === "destroy") {
self.constructor.remove(self)
} else {
self.constructor.add(self)
}
};

Expand Down
7 changes: 7 additions & 0 deletions test/tests/model.js
Expand Up @@ -270,3 +270,10 @@ test("#initialize", function() {

ok(post.initialized)
})

test("saving a model with an id should add it to the collection if it isn't already present", function() {
var Post = Model("post")
var post = new Post({ id: 1 }).save()

ok(Post.first() === post)
})

0 comments on commit c8755af

Please sign in to comment.