Results 1 to 2 of 2

Thread: Schema and proxy

  1. #1

    Join Date
    Jan 2014
    Posts
    19
    Answers
    1
    Vote Rating
    2
      1  

    Default Schema and proxy

    I am trying to create a base model (Ext.data.Model), that defines a schema, namer and proxy. The API that we are using has default endpoints that are pluralized entity names, for example "Shelf" will become "Shelves".

    We have a proxy that looks like this defined on the base model but I have noticed that since the framework does a run then replace method, it doesn't work as expected and was wondering if anyone can give some help in terms of trying to get this to work as expected.

    Code:
    proxy:{ 
      type: 'rest', 
      actionMethods:{ 
        create: 'POST', 
        read: 'GET',
        update: 'PUT', 
        destroy: 'DELETE' 
      },
      url: apiURL + Ext.util.Inflector.pluralize('{entityName}'), 
      reader: { 
        type: 'json', 
        dateFormat: 'C', 
        rootProperty: 'data' 
      }
    }
    The issue we have is that when my entityName is "Shelf", it then pluralizes '{entityName}' to '{entityName}s, and then when entityName is put in the template, it then runs the Inflector on Shelfs, and doesn't turn it into Shelves as expected.

    I poked around a bit in the schema and proxy classes to find a better way to do this without having to create more properties on the model, but can't find a better direction. Does anyone have some suggestions?

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    18,693
    Answers
    691
    Vote Rating
    889
      0  

    Default

    The problem is that the template formatting doesn't have access to the inflector methods. Try something like this:

    Code:
    Ext.define('MyApp.model.Base', {
            extend: 'Ext.data.Model',
    
            requires: ['Ext.util.Inflector'],
    
            schema: {
                namespace: 'MyApp.model',
                proxy: {
                    type: 'rest',
                    actionMethods: {
                        create: 'POST',
                        read: 'GET',
                        update: 'PUT',
                        destroy: 'DELETE'
                    },
                    url: '/api/{entityName:inflectorPlural}',
                    reader: {
                        type: 'json',
                        dateFormat: 'C',
                        rootProperty: 'data'
                    }
                }
            }
        }, function() {
            var I = Ext.util.Inflector;
            Ext.util.Format.inflectorPlural = I.pluralize.bind(I);
        });
    
        Ext.define('MyApp.model.Shelf', {
            extend: 'MyApp.model.Base'
        });
    
        console.log(MyApp.model.Shelf.getProxy().getUrl());
    Evan Trimboli
    Twitter - @evantrimboli

Similar Threads

  1. [OPEN] Schema changing the proxy url
    By skirtle in forum Ext 5: Bugs
    Replies: 3
    Last Post: 18 Apr 2016, 12:36 AM
  2. [DUP] Bug on treepanel when setting a proxy rootProperty on a schema
    By Psychokrameur in forum Ext 5: Bugs
    Replies: 2
    Last Post: 22 Apr 2015, 11:21 AM
  3. Replies: 1
    Last Post: 21 Nov 2014, 3:36 AM
  4. Schema changing the proxy url
    By skirtle in forum Ext 5: Q&A
    Replies: 1
    Last Post: 15 Aug 2014, 12:00 PM
  5. Model's Schema (and Proxy) must be hardcoded?
    By brian428 in forum Ext 5: Q&A
    Replies: 9
    Last Post: 21 May 2014, 8:14 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •