All my data lives in a SQL database behind a RESTful API. I'm having a heck of a time trying to understand how ExtJS' 'belongsTo' and 'hasMany' associations work. The name sound simple, but I cannot figure out what ExtJS is using properties like 'foreignKey', 'primaryKey', 'associationKey', etc. to actually mean.
Every table in my DB has a primary key, available in the JsonRest API as the 'id' property. Those that have foreign keys present the fk in records as a 'resource_uri' pointing to the related RESTful resource.
How does this work with ExtJS' terminology?
Given t1 and t2:
| id(Primary Key) |
value |
| 1 |
'foo' |
| 2 |
'bar' |
and
| id (Primary Key) |
related (Foreign Key) |
value |
| 1 |
2 |
'asdf' |
| 2 |
1 |
'fdsa' |
asking for '/api/t2/2/' gives me
Code:
{'meta': ..., 'objects': [{'id' : '2', 'related' : '/api/t1/1/', 'value' : 'fdsa', 'resource_uri' : '/api/t2/2/'}]}
I want my ExtJS Model (and its associated proxy and store) to know that it should fetch the 'id' and 'value' from the provided uri. What do I need to set my Ext.data.association.Association parameters to to accomplish this?
Note: I saw this discussion of the same topic:
http://stackoverflow.com/questions/6...ons-and-stores
I
don't recommend using associations in real world projects. At least now. Instead use approach which is shown in your example: Model+Store+Filtering.
I am curious to know if anyone has actually used associations in real projects.