Open gabriel-dehan opened 9 years ago
My take on this issue is the following :
For instance if I have a user
model with a post
belongsTo relation, it will create a relationMap object on the post
record :
somePostRecord.get('relationMap') === {
user: 2 // Where 2 is the id of the user
}
post
model I would like to do the following : // Imports and stuffs
MyPostModel = Model.extend({
// attributes
});
MyPostModel.adapter = Adapter.create();
MyPostModel.url = "user/:user_id/post";
// export and stuff
My Adapter
should request user/2/post
and get the post.
Ember.RESTAdapter
. Mainly the buildURL
method, that will now parse the url for a dynamic segment and search in the relationMap the corresponding id.
For instance "user/:user_id/post" will look for the "user" key in the relationMap property of the record.The code can be found here :
You'll notice how it was necessary to define a modelName
attribute for the application model. I don't like it much but haven't figured a way out of this definition.
With minor changes, this could actually be implemented directly in the default Ember.RESTAdapter
and Ember.Model
.
What do you guys think of it ?
Hello !
I was looking for a way of having a dynamic part in my model's url. Something like this :
But that does not work from the get go obviously. I thought of overwriting the buildURL function in my own adapter but we only get the record (before it's fetched, with nothing but a primary key) and I can't manage to get its belongsTo. Is there a built in way to do this or should there be one ?
Thanks !