Skip to content
Permalink
Browse files

Add `has` method to find out if a record with a given id is loaded

Alias `has` method on the model class
  • Loading branch information...
tchak committed Jul 8, 2012
1 parent 0047d67 commit b63b84b07d203e4467df034a1c19c37de20648a2
@@ -341,6 +341,7 @@ var storeAlias = function(methodName) {
};

DS.Model.reopenClass({
has: storeAlias('has'),
find: storeAlias('find'),
filter: storeAlias('filter'),

@@ -511,6 +511,10 @@ DS.Store = Ember.Object.extend({
return array;
},

has: function(type, id) {
return !Ember.none(this.typeMapFor(type).idToCid[id]);
},

// ............
// . UPDATING .
// ............
@@ -46,6 +46,19 @@ test("the filter method should be aliased", function() {
Person.filter(filter);
});

test("the has method should be aliased", function() {
expect(2);

var id = 1;

store.has = function(type, passedId) {
equal(type, Person, "has called with correct type");
equal(passedId, id, "has was called with correct arguments");
};

Person.has(id);
});

test("the create method should raise an exception", function() {
raises(function() {
Person.create();
@@ -510,3 +510,8 @@ test("when a record depends on another record, we can delete the first record an
equal(get(parentComment, 'isDirty'), false, "parent comment has been saved");
ok(true, "no exception was thrown");
});

test("can ask if record with a given id is loaded", function() {
equal(store.has(Person, 1), true, 'should have person with id 1');
equal(store.has(Person, 4), false, 'should not have person with id 2');
});

0 comments on commit b63b84b

Please sign in to comment.
You can’t perform that action at this time.