Results 1 to 7 of 7

Thread: Association Issue

  1. #1
    Sencha Premium User
    Join Date
    Nov 2016
    Posts
    6

    Default Association Issue

    I am trying to show an association in a grid. Like this.

    Code:
    Ext.define('regression.model.Project', {    
        extend: 'Ext.data.Model',
    
        fields: [
            { name: 'name', type: 'string' },
            { name: 'id', type: 'int' }
        ],
    
        idProperty: 'id'
    
    });
    Code:
    Ext.define('regression.model.Models', {    
        extend: 'Ext.data.Model',
    
        requires: [
            'Ext.data.proxy.Ajax',
            'Ext.data.reader.Json',
            'Ext.data.writer.Json',
            'regression.model.Project'
        ],
    
        fields: [
            { name: 'name', type: 'string' },
            { name: 'modelId', type: 'int' },
            {
                name: 'projectId', type: 'int', reference: 'Project'
            },
            { name: 'description', type: 'string' },
            { name: 'published', type: 'bool' },
            { name: 'extras', type: 'auto' }
        ],
    
    
        idProperty:'modelId'
    }
    Code:
                             {                  
                            xtype: 'templatecolumn',
                            tpl: '{projectId.name}',
                            width: '50%',
                            editor: {
                                xtype: 'combobox',
                                editable: false,
                                forceSelection: true,
                                mode: 'local',
                                store: 'Projects',
                                triggerAction: 'all',
                                queryMode: 'local',
                                displayField: 'name',
                                valueField: 'id'
                            }             
    
                        }
    But this always prints nothing in the grid. tpl:'{projectId}' shows the id and I don't get an error that the name property isn't found. It just doesn't render in the grid.

  2. #2
    Sencha Premium User
    Join Date
    Nov 2016
    Posts
    6

    Default

    Is this possible or do I need to use a render? I don't understand the value of associations if you can't do things like this.

    Trevor

  3. #3
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,254
    Answers
    759

    Default

    There's too much code missing to answer as-is, so here's a simple example:

    https://fiddle.sencha.com/#view/editor&fiddle/1sm4
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  4. #4
    Sencha Premium User
    Join Date
    Nov 2016
    Posts
    6

    Default

    Thanks. I have modified your fiddle to show the issue I am facing. The data from the stores is independent and relatable with the foreign key but not loaded together.

    https://fiddle.sencha.com/#view/editor&fiddle/1sm6

  5. #5
    Sencha Premium User
    Join Date
    Nov 2016
    Posts
    6

    Default

    Do the associations only work with nested data?

  6. #6
    Sencha Premium User
    Join Date
    Nov 2016
    Posts
    6

    Default

    Is there a way to associate records in 2 different stores if loaded from separate backend calls?

  7. #7

    Default

    Hello Evan,


    I've created a simple project with your fiddle example, just replacing the class path according to my needs, for example from 'regression.model.Base' to 'MyAppName.model.Base', and during the store loading method, when it tries to get the models (store.first().models) it fails with the following exception:


    TypeError: store.first(...).models is not a function
    at constructor.<anonymous> (http://localhost:1841/app/view/main/...10560799:22:38)
    at constructor.triggerCallbacks (http://localhost:1841/ext/build/ext-...60800:77010:22)
    at constructor.setCompleted (http://localhost:1841/ext/build/ext-...60800:76971:12)
    at constructor.setSuccessful (http://localhost:1841/ext/build/ext-...60800:76984:18)
    at constructor.process (http://localhost:1841/ext/build/ext-...60800:76883:16)
    at constructor.processResponse (http://localhost:1841/ext/build/ext-...60800:85771:23)
    at constructor.<anonymous> (http://localhost:1841/ext/build/ext-...60800:86362:16)
    at Object.callback (http://localhost:1841/ext/build/ext-...560800:8169:32)
    at constructor.onComplete (http://localhost:1841/ext/build/ext-...60800:24686:13)
    at constructor.onStateChange (http://localhost:1841/ext/build/ext-...60800:24626:16)


    Do you have any idea of what is wrong?


    Thanks in advance


    Rafael

  8. #8
    Sencha Premium User
    Join Date
    Apr 2015
    Location
    Germany
    Posts
    122
    Answers
    1

    Default

    I used a session, an override of Role and a manual refresh after load of associated data to make this work: (Preview doesn't seem to work here, use "open in fiddle"!)



    Not tested with keyless associations.

Similar Threads

  1. hasMany association issue
    By phimaur in forum Ext JS 6.x Q&A
    Replies: 3
    Last Post: 11 Aug 2015, 8:00 AM
  2. Issue with Post: Model have one to many association.
    By basitelahi in forum Ext 5: Q&A
    Replies: 1
    Last Post: 31 Dec 2014, 9:43 AM
  3. Issue when hasOne association is null
    By Basta in forum Sencha Touch 2.x: Q&A
    Replies: 8
    Last Post: 21 Apr 2014, 8:42 AM
  4. Replies: 1
    Last Post: 13 Mar 2014, 6:20 AM
  5. Replies: 2
    Last Post: 10 Apr 2012, 10:27 AM

Posting Permissions

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