I want to re-query for new data on the backend every time someone clicks a link for a nested resource. At first I thought this was going to be a simple process but ember doesn’t seem to like hitting the database to collect information on a model that is already in store.
Say for a example I have some list of links that point to some posts and when a use clicks on those posts I want detailed data for each one of those posts to be displayed to the user. When the user view goes to the page this list is on, JSON is served up that looks a lot like this
{
posts:[
{
id: '1',
title: 'Post A'
},
{
id: '1',
title: 'Post A'
},
{
id: '2',
title: 'Post B'
},
{
id: '3',
title: 'Post C'
},
]
}
My posts route is setup to execute a findAll and load up a bunch of posts models for me
App.Router.map ()->
@resource 'posts', ->
@resource 'post', { path: ':post_id' }
App.PostsRoute = Ember.Route.extend
model: ->
@store.findAll('posts')
App.PostRoute = Ember.Route.extend
model (params): ->
@store.find('post', params.post_id)
The list renders out fine. The template contains an outlet
for a PostView
to render into so that user can click from post to post and have the details of each post displayed to him on the same page as the post list.
The trick is getting post date like Author, Content, Comments into these Post
models that I have loaded into the store. I thought that when a user clicked on the #/posts/1
link the PostView
would render into the outlet I have setup but that is not happening. It seems that @store.find
just sees that there is a post with the given ID already in the store and just serves that up. How can I force him to query for the detailed data for a post stored at /posts/:id
?
If it helps anyone. I can commit a small rails/ember project on github containing my example.
The resourced in these links:
helped me some but I still cannot get the desired behavior.
TLDR; @store.find
doesnt re-query the backend API when a model already exists in store w/given ID.