Results 1 to 3 of 3

Thread: Attempting to save a model object with a hasMany association - association data empty

  1. #1
    Sencha Premium Member
    Join Date
    Mar 2011
    Location
    Betelgeuse VII
    Posts
    101
    Answers
    4

    Default Answered: Attempting to save a model object with a hasMany association - association data empty

    Hello,

    I have the following model:

    Code:
    Ext.define('Canvas.model.CanvasModel', {
        extend: 'Ext.data.Model',
    
        requires: ['Canvas.model.CanvasObjectModel'],
    
        fields: [
            {
                name: 'canvasId',
                type: 'int'
            },
            {
                name: 'title',
                type: 'string'
            },
            {
                name: 'definition',
                type: 'string'
            }
        ],
    
        hasMany: [{ model: 'CanvasObjectModel', name: 'CanvasObjects'}],
    
        proxy: {
            type: 'rest',
            url: '/MyApp/Canvas',
            timeout: 120000,
            noCache: false,
    
            reader:
            {
                type: 'json',
                root: 'data',
                successProperty: 'success'
            },
            writer:
            {
                type: 'json',
                writeAllFields: true
            }
        }
    });
    And an associated model:

    Code:
    Ext.define('Canvas.model.CanvasObjectModel', {
        extend: 'Ext.data.Model',
    
        fields: [{
            name: 'ObjectId',
            type: 'int'
        }],
    
        belongsTo: 'CanvasModel'
    });
    I add data to the 'CanvasModel' and then set the associated model:

    Code:
    var canvasModel = Ext.create('Canvas.model.CanvasModel', {
                canvasId: 1,
                title: title,
                definition: "test"
    });
    
    var obj = Ext.create('Canvas.model.CanvasObjectModel', {
       ObjectId: 1
    });
    
    canvasModel.set('CanvasObjects', obj);
    When I inspect the canvasModel variable it appears the CanvasObjects property has data, however when I try:

    Code:
    canvasModel.getAssociatedData();
    The returned object is empty. When I pass the object server-side the properties for the canvasModel are all set (canvasId, title, definition) but the assoicated data is null.

    I'm very new to this so it's possible I'm doing this all wrong. Any idea on how I might set and get the associated data? BTW, I'm using extjs4.1 RC2.

    Thank you.

  2. Take a look at a very similar question here :

    http://www.sencha.com/forum/showthre...a-single-Store

  3. #2

  4. #3
    Sencha Premium Member
    Join Date
    Mar 2011
    Location
    Betelgeuse VII
    Posts
    101
    Answers
    4

    Default

    Thanks for the link.

Posting Permissions

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