Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Association trouble

  1. #1

    Default Answered: Association trouble

    Hello, I need to get some data from referenced model to show in a grid.
    So it just not working

    Help please, what i'm doing wrong?

    https://fiddle.sencha.com/#fiddle/1j1e

  2. Here is a simple example where nested objects are not used:


  3. #2
    Sencha Premium User
    Join Date
    Apr 2007
    Location
    Vienna, Austria
    Posts
    59

    Default

    At first glance it seems like you should use a keyed association instead of a keyless one. So a "reference" instead of "hasOne". (Also foreignKey is spelled wrongly..).

    I also think that you would need a renderer for the grid column to show the data retrieved through the association.

    Furthermore I don't understand why the foreign key field is called "id". That is very confusing and probably wrong. Shouldn't it be called something like 'users_count_id'?


    lg,
    Horst

  4. #3
    Sencha Premium Member richardvd's Avatar
    Join Date
    Jun 2011
    Location
    NL
    Posts
    255
    Answers
    22

    Default

    One approach I like is to send nested data from the server in a single request. This Fiddle by @evant (updated to Ext JS 6.2) demonstrates this approach. Here, a templatecolumn is used for displaying the associated values. It also shows how to edit the associated data.


  5. #4

    Default

    Well, when data is present as nested object and come from the server in a single request it's no problem, all things works properly. Problem actually when it present in various store and come with multiple requests.

    Thank you anyway -)

  6. #5
    Sencha User
    Join Date
    Apr 2013
    Posts
    913
    Answers
    105

    Default

    Here is a simple example where nested objects are not used:


  7. #6

  8. #7
    Sencha User
    Join Date
    Mar 2016
    Posts
    39
    Answers
    1

    Default

    Quote Originally Posted by hakimio View Post
    Here is a simple example where nested objects are not used:

    Very nice fiddle you did!

    I'm trying to implement it in my own app and found some problems:

    First, if we disable all session: true lines in your fiddle, association becomes broken. I don't know how session works, but dependence on this mechanism makes me change some things in my app.
    Without session I can't get value here:
    PHP Code:
    genderRenderer: function(valuemetarecord) {
        
    console.log(record.getGender()); //<-- I see all values here
        
    console.log(record.getGender().get('name')); //<-- NO VALUE here!    
        
    return record.getGender().get('name');

    Second, I added session: true to my Store (not in stores object of ViewModel) and got an error:
    PHP Code:
    TypeErrorsession.adopt is not a function 
    But it working when I build the same Store in ViewModel:
    PHP Code:
    stores: {        
        
    employees: {            
            
    model'employees.Employees',
            
    autoLoadtrue,
            
    sessiontrue,
            
    groupField'positionId',
            
    remoteSorttrue,
            
    remoteFiltertrue,
            
    sorters: {                
                
    direction'ASC',                
                
    property'lastname'
            
    }   
         },


  9. #8
    Sencha User
    Join Date
    Apr 2013
    Posts
    913
    Answers
    105

    Default

    Quote Originally Posted by Sogl View Post
    if we disable all session: true lines in your fiddle, association becomes broken. I don't know how session works, but dependence on this mechanism makes me change some things in my app.
    Yes, session is required to manage model associations. I would suggest to take a look at documentation, blog post and excellent presentation by Don Griffin.

    I added session: true to my Store (not in stores object of ViewModel) and got an error
    Not sure why your session doesn't have adopt() method. Maybe, it was never instantiated and it tried to call adopt() on a boolean ("true") instead of an actual session instance. Anyway, even if you assigned session to global store, its contents would not be tracked in session (thread #1 and thread #2).

  10. #9
    Sencha User
    Join Date
    Mar 2016
    Posts
    39
    Answers
    1

    Default

    Quote Originally Posted by hakimio View Post
    Really nice presentation, thx! Things cleared up for a bit.

    Quote Originally Posted by hakimio View Post
    Not sure why your session doesn't have adopt() method. Maybe, it was never instantiated and it tried to call adopt() on a boolean ("true") instead of an actual session instance. Anyway, even if you assigned session to global store, its contents would not be tracked in session (thread #1 and thread #2).
    I solved this problem with adding entityName parameter. After that I also tried to recreate my bug without success

    My model stores conf:
    PHP Code:
    stores: {
        
    employees
        {
            
    type'employees',
            
    sessiontrue
        
    },
        
    positions: {
            
    type'positions',
            
    sessiontrue
        
    }

    Works fine! Except for one case.

    My app based on admin-dashboard template and I use setCurrentView function to switch card layouts. When I log-out from my app, last route stored somewhere and after next login my grid with filtering and grouping on associated field isn't loaded. Console error msg:
    Code:
    Ext.util.Event.fire(): Attempting to fire "beforereconfigure" event on destroyed Ext.grid.feature.Grouping instance with id: unknown
    Ok. I disabled grouping feature and after that saw another error:
    Code:
    [E] Ext.util.Event.fire(): Attempting to fire "reconfigure" event on destroyed Ext.grid.filters.Filters instance with id: gridfilters
    But after page refresh all works fine.

    Parts of grid js file with features/plugins:
    PHP Code:
    ...
    requires: [
        ...
        
    'Ext.grid.feature.Grouping',
        
    'Ext.grid.filters.Filters'
    ],
    ...
    features: [Ext.create('Ext.grid.feature.Grouping', {
        
    expandTip'Нажмите чтобы развернуть. Клавиша CTRL свернет все остальные группы.',
        
    collapseTip'Нажмите чтобы свернуть. CTRL/клик свернет все остальные группы.'
    })],
    ...
    plugins: [
         
    Ext.create('Ext.grid.filters.Filters', {
             
    menuFilterText'Фильтр'
        
    }
    )],
    ... 

  11. #10
    Sencha User
    Join Date
    Mar 2016
    Posts
    39
    Answers
    1

    Default

    Solved by:
    PHP Code:
    features: [{
        
    ftype'grouping',
        
    expandTip'Нажмите чтобы развернуть. Клавиша CTRL свернет все остальные группы.',    
        
    collapseTip'Нажмите чтобы свернуть. CTRL/клик свернет все остальные группы.'
    }],

    plugins: {ptype'gridfilters'menuFilterText'Фильтр'}, 
    I don't know why grid don't like Ext.Create in this case

    One question. How grid knows what store should be used for the association? In grid I set only one store.

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 14 Nov 2016, 5:51 AM
  2. [CLOSED] model subclass association bug - duplicate association
    By mderer in forum Ext 5: Bugs
    Replies: 3
    Last Post: 31 Jul 2014, 5:50 AM
  3. Replies: 1
    Last Post: 13 Mar 2014, 6:20 AM
  4. Replies: 0
    Last Post: 15 May 2012, 6:31 PM
  5. Replies: 2
    Last Post: 10 Apr 2012, 10:27 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
  •