View Full Version : How to determine which model a model belongsTo?

5 Mar 2012, 5:28 AM
Ok, so the title of this thread may be a bit confusing, let me try to explain my problem.

I am currently interfacing an existing application build with ExtJS to a new API provided by a third party. The API is somewhat unorthodox as it requires a JSON object, which holds an invocation string with the complete API path of whatever action you want to

Say for example you need to get the list of alle users from vendor 1, you have to send an invocation (as string)


My idea is to mimic their data layout, by using Ext.data.Model with associations (BelongsTo, HasMany), and then extend Ext.data.Writer.json to build the invocation string according to the API specs.

So when I have a model 'Users', which belongsTo the model 'Vendor', and I call Vendor.Users.load(), my custom writer's buildRequest() method gets called which has to build the invocation string. How do I determine that this.model() belongs to an instance of 'Vendor', so I can build the invocation string?

5 Mar 2012, 9:15 AM
Something like:

var associations = rec.associations;

associations.each(function(association) {
if (association.type = 'belongsTo') {