emberjs/data — Issue #146: filters should update after xhr requests complete (RESTAdapter)
Author: hjdivad
Created: 2012-03-08 01:26:09+00:00
State: open

Filters do not update when properties that come back from the server differ from those on the client. The most obvious one is `id`, during creation.

## Steps to reproduce
- Create a filter that filters model on `id`, e.g.

```javascript
persisted = App.store.filter( MyType, function( data ) {
return data.get('id'); // only return persisted records
});
```

- Create an instance in the store

```javascript
MyType.createRecord();
```

- Commit the store, causing the XHR request to fire.

```javascript
App.store.commit();
```

## Expected Results

`persisted` should be updated after the XHR request completes.

## Actual Results

`persisted` is not updated.

## Unit Test

```javascript
// model_array_test.js
test("the filter function gets called when server side changes occur with the model", function() {
var store = DS.Store.create({
adapter: DS.Adapter.create({
updateRecord: function(store, type, model) {
store.didUpdateRecord(model, JSON.stringify({id: 1, name: "Scumbag Server-side Name"}));
}
})
});

store.loadMany(Person, array);

var modelArray = store.filter(Person, function(hash) {
if (hash.get('name').match(/Scumbag/)) { return true; }
});

equal(get(modelArray, 'length'), 3, "The filter function should work");

Ember.run(function() {
store.find(Person, 1).set('name', 'Client-side Name');
});

equal(get(modelArray, 'length'), 2, "The filter function should respect client side changes");

Ember.run(function() {
store.commit();
});

equal(get(modelArray, 'length'), 3, "The filter function should respect server side changes ");
});

```