Results 1 to 4 of 4

Thread: hasMany association issue

  1. #1
    Sencha Premium User
    Join Date
    Oct 2011
    Location
    Paris
    Posts
    21

    Default Answered: hasMany association issue

    Hi guys

    This code returns an empty collection in ST2.4 but fails in EXTJS6.
    Am I setting the hasMany association correctly here?

    Thanks
    Philippe

    Code:
    Ext.define('App.model.Hotel', {
        extend: 'Ext.data.Model',
        config: {
            fields: [
                { name: 'id', type: 'int' },
                { name: 'name', type: 'string' },
                { name: 'address', type: 'string' },
                { name: 'status', type: 'int' }
            ],
            hasMany: {
                model: 'App.model.Room',
                name:'rooms'
            }
        }
    });
    
    
    Ext.define('App.model.Room', {
        extend: 'Ext.data.Model',
        requires: ['Ext.data.Store'],
        config: {
            fields: [
                { name: 'id', type: 'int' }
                ]
        }
    });
            
    
    
    Ext.application({
        name : 'Fiddle',
    
    
        launch : function() {
            
            var hotel = Ext.create("App.model.Hotel");
            console.log( hotel.rooms() );
            
            
        }
    });

  2. Quote Originally Posted by phimaur View Post
    Hi guys

    This code returns an empty collection in ST2.4 but fails in EXTJS6.
    Am I setting the hasMany association correctly here?

    Thanks
    Philippe
    Hi--

    It should work if you remove the fields and hasMany from config:{}.

    Thanks
    Joel

  3. #2
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Quote Originally Posted by phimaur View Post
    Hi guys

    This code returns an empty collection in ST2.4 but fails in EXTJS6.
    Am I setting the hasMany association correctly here?

    Thanks
    Philippe
    Hi--

    It should work if you remove the fields and hasMany from config:{}.

    Thanks
    Joel

  4. #3
    Sencha Premium User
    Join Date
    Oct 2011
    Location
    Paris
    Posts
    21

    Default

    That worked.
    You made my day.

    Thanks
    Philippe

  5. #4
    Sencha User joel.watson's Avatar
    Join Date
    Nov 2014
    Posts
    3,120
    Answers
    446

    Default

    Quote Originally Posted by phimaur View Post
    That worked.
    You made my day.

    Thanks
    Philippe
    Excellent, glad it worked!

    Thanks
    Joel

Similar Threads

  1. Replies: 5
    Last Post: 14 Nov 2014, 4:18 AM
  2. [FIXED] Can't have more than 1 hasMany association
    By stormin_walker in forum Sencha Touch 1.x: Bugs
    Replies: 20
    Last Post: 18 Dec 2013, 7:27 AM
  3. Replies: 2
    Last Post: 10 Apr 2012, 10:27 AM
  4. Can't have more than 1 hasMany association
    By stormin_walker in forum Sencha Touch 1.x: Discussion
    Replies: 13
    Last Post: 1 Sep 2011, 6:09 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
  •