PDA

View Full Version : ExtJS data.association.Association to RDBMS mapping help or tutorial?



justinzane
15 May 2012, 6:31 PM
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


{'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/6622878/extjs-4-models-with-associations-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.