Processing an incomplete or summary list of objects returned by GET / models using ember-data

For a resource message,
How to handle the following scenario.

GET / posts returns an array with only the total (i.e. title, commentCount)
but GET / post /: id returns the full object. (i.e. title, content, comments: [comment1, comment2])

When the application is loaded, a list of messages is displayed on the screen, I call App.Post.find () to receive all messages.
And when the element is clicked, if I try to load using App.Post.find (1) , it will return the element of cached data. One way is to force download full mail from the server.

Edit
Found a relevant topic: https://github.com/emberjs/data/issues/51
I understand that this is not a semantically correct way to support REST.
But another utility: the record can be updated on the server, I want to update it, how to do it?

+5
source share
2 answers

You can use the model method .reload()to retrieve it from the adapter. Therefore, on your route, where you get outdated data, instead of returning this.store.find('post', 1), return it this.store.find('post', 1).reload().

0
source

All Articles