4
votes

After building a rest api for my data structure, I want to implement it into Extjs. After reading the documentations here and ofcourse searching on stackoverflow and google, i still get errors when setting it up.

I have a rest route that looks like this:

/api/products/:id

and each product has a collection of categories that can be accessed using

/api/products/3/categories.

After creating my model for the product like so:

Ext.define('Product', {
    extend: 'Ext.data.Model',
    fields: [
        'id',
        'and all the other properties here...'
    ],

    proxy: {
        type: 'rest',
        url : '/api/products'
    }
});

And ofcourse doing the same for the categories, exept then to the route

/api/categories/:id

These models on their own DO WORK. I can create, update, read and delete a product or category without any trouble.

Next up i tried to make the associations to properly link them. there are a few things i have tried, all without any success:

  1. Apply configs like this link says
  2. Apply configs like another link says
  3. Create an own custom proxy like explained here

Either the result does nothing, or creates an empty association store with no model. I have no clue what I'm doing wrong, and most info on google is highly outdated. PLEASE HELP!

Thanks in advance

1
If your category model proxy's url is /api/categories, how can you expect product's cats to be loaded from /api/products/3/categories?Greendrake
@DrakeES The original category model should be able to be used without the product (CRUD action for a category). However, since the i use the REST proxy and the associations, i want to get a link that generates the url /api/products/3/categories when I try to load the categories of the product with id 3. Any idea how to do this, or perhaps a better way to accomplish this?Nick

1 Answers

0
votes

So the docs at http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.data.proxy.Rest say this:

If further customization is needed, simply implement the buildUrl method and add your custom generated url onto the Request object that is passed to buildUrl. See Rest proxy's implementation for an example of how to achieve this.

What I would do is set an XHR breakpoint in your dev tools for the XHR request that is made when you load your categories for a product and see what methods it goes through to build the URL. And then I would go from there and see where an customization is necessary.