Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion spec/javascripts/resourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('A Resource instance', function() {

it('should not have a URL', function() {
expect(model.resourceURL()).toBeUndefined();
})
});
});

it('allows setting of properties not in the schema during creation', function() {
Expand Down Expand Up @@ -80,4 +80,18 @@ describe('A Resource instance', function() {
});
});

describe('finding objects via find', function() {
beforeEach(function() {
model = Model.create({id: 1});
});

it('should return model for the given primary key if it exists', function() {
expect(Model.find(1)).toBe(model);
});

it('should return null if no model with the given primary key exists', function() {
expect(Model.find(2)).toBeNull();
});
});

});
7 changes: 7 additions & 0 deletions src/sproutcore-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,13 @@
return this;
},

find: function(id) {
if (SC.none(this.identityMap)) {
return null;
}
return this.identityMap[id] || null;
},

// Create an instance of this resource. If `options` includes an
// `id`, first check the identity map and return the existing resource
// with that ID if found.
Expand Down