Data: store.find with query params appears to break data binding when calling createRecord

Created on 10 May 2015  路  5Comments  路  Source: emberjs/data

I posted a question over on Stackoverflow but I was able to replicate this in a simple jsbin and I'm now thinking this might be a bug so wanted to flag it here (sorry for the double post if this is not a bug and is user error)

When the routes model uses store.find('modelName') and you call createRecord in the controller the model is updated with the new record and the template updates as expected.

However, if you use the query param version of store.find in the model (i.e., store.find('modelName', {usesParams: true}), the template no longer updates when calling createRecord.

Here is a JSBin illustrating the issue:

http://jsbin.com/sonudapota/2/edit

Is this expected behavior? User error? a bug? My expectation was that the template would update in the same way when using find with query params as when using find without query params for the model.

Here are the versions I'm using:

runner-3.26.2.min.js:1 DEBUG: Ember      : 1.11.3
runner-3.26.2.min.js:1 DEBUG: Ember Data : 1.0.0-beta.16.1
runner-3.26.2.min.js:1 DEBUG: jQuery     : 1.11.3

Most helpful comment

What's the advised way of achieving this now that store.filter is deprecated?

All 5 comments

Using store.find(type, query) does not return a live RecordArray so the behavior you're describing is correct.

You should be able to use store.filter(type, query, filter) (docs) instead.

The reason for store.find(type, query) not updating with the newly created record is that query is just sent to the server, there's no way for ED to know if new records "match" that query or not. Sometimes the query might be a simple filter like { isUnread: true } but it can also be something like { since: '2015-05-10 10:51' }. Using store.filter(type, query, filter) on the other hand, passing both query and a filter callback function, ED can pass query to the server and use the filter function on all new records to know if it's to be included in the live RecordArray or not.

Thank you for the explanation. That makes sense.

What's the advised way of achieving this now that store.filter is deprecated?

@wayne-o did you ever find an answer to this?

I am facing the same issue. Any solution for this?

Was this page helpful?
0 / 5 - 0 ratings