I am trying to do something that sounds simple, but I cannot find a solution.
My application should edit documents containing pages.
Here is my model:
MyApplication.Document = DS.Model.extend({ title: DS.attr('string'), pages: DS.hasMany('page', {async: true}) }); MyApplication.Page = DS.Model.extend({ document: DS.belongsTo('document', {async: true}), title: DS.attr('string'), params: DS.attr(), objects: DS.attr() });
And routes:
MyApplication.Router.map(function () { this.resource('document', {path: '/document/:document_id'}); }); MyApplication.Document = Ember.Route.extend({ model: function (params) { return this.store.find('document', params.document_id); } });
When I download document 1, the application call is http://www.myserver.com/api/document/1 .
The problem is that when I want to find a document page, it calls
http://www.myserver.com/api/pages/ID
instead
http://www.myserver.com/api/document/1/pages/ID
Nested abstract urls are important in my application.
I found various things on this subject, for example by adding links to the JSON response:
{ "document": { "id": "1", "title": "Titre du document", "pages": ["1", "2", "3"], "links": {"pages" : "pages"} },
But when I call the pages, it asks for http://www.myserver.com/api/document/1/pages without an identifier.
I will also try to specify the document when I request the page:
this.store.find("page", 1, {document:1});
It is not possible to find complete documentation on this, therefore, if someone can explain to me what happened, I will be happy.
Thanks.