I am accessing a REST service which exposes these two resources, a parent resource and a child resource:
/users
/users/{userId}/account
So the resource "account" is not nested within the resource "user", it has to be accessed by a second request. There are examples for such REST APIs, e.g. here
I use these models to map users and their account to the Ext Js 4 data model:
User
Ext.define("MyApp.model.User", {
extend: "Ext.data.Model",
fields: [ { name: "id", type: "string" }],
associations: [{
model: "MyApp.model.Account",
name: "account",
type: "hasOne",
reader: "json",
getterName: "getAccount",
setterName: "setAccount",
foreignKey: "accountId"
}
],
proxy: {
type: "rest",
url: "/rest/users",
reader: {
type: "json",
totalProperty: "total",
root: "users"
}
}
});
Account
Ext.define("MyApp.model.Account", {
extend: "Ext.data.Model",
fields: [ { name: "id", type: "string" }],
belongsTo: "MyApp.model.User",
proxy: {
type: "rest",
reader: { type: "json"}
}
});
The account proxy does not have a url (I hoped this would be created based on the parent user model). When I call user.getAccount() I get an exception because the proxy is missing the url.
Question: Is there some way to setup the models such that Ext Js will access /users/{userId}/account WITHOUT updating the account proxy url manually with each parent userId?