1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    5
    Vote Rating
    0
    jst@pe is on a distinguished road

      0  

    Default Unanswered: HasMany Association not saved by REST proxy

    Unanswered: HasMany Association not saved by REST proxy


    Hi,

    I am trying to use the HasMany Association between to models. I can load it fine but I can't save new associations using a REST proxy.

    I have the models Substance and SubstanceGroup. A substance group contains many substances and a substance may be used in several groups.

    I've got one REST resources substance for the substances and another REST resource substance_group for the substance groups.

    My current model classes look like:
    Code:
    Ext.define('substance_groups.model.Substance', {
        extend: 'Ext.data.Model',
    
    
        idProperty: 'id',
    
    
        fields: [
            {
                name: 'id',
                type: 'string'
            },
            {
                name: 'name'
            }
        ],
        proxy: {
            type: 'rest',
            url: '../../../../../api/substance'
        }
    });
    
    Ext.define('substance_groups.model.SubstanceGroup', {
        extend: 'Ext.data.Model',
    
    
        requires: [
            'substance_groups.model.Substance'
        ],
        uses: [
            'substance_groups.model.Substance'
        ],
    
    
        idProperty: 'id',
    
    
        fields: [
            {
                name: 'id'
            },
            {
                name: 'name',
                type: 'string'
            }
        ],
        hasMany: {
            model: 'substance_groups.model.Substance',
            autoLoad: true,
            name: 'substances'
        },
        proxy: {
            type: 'rest',
            url: '../../../../../api/substance_group'
        }
    });
    When I add substances to a group using the store group.substances() it is displayed fine. Yet when I save it no substances are transferred.

    What I would like to see is something like:
    Code:
    POST api/substance_group
    {
      id: '242',
      name: 'My Group',
      substances: [
        {
           substance_id: '123'
        },
        {
           substance_id: '456'
        }
      ]
    }
    Any hints on how to do that? Help very much appreciated!!

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,347
    Answers
    3542
    Vote Rating
    846
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    I don't believe store syncing work with associations, least last I tried while back.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    May 2012
    Posts
    5
    Vote Rating
    0
    jst@pe is on a distinguished road

      0  

    Default


    Ok thanks. I thought so too and started building the JSON manually which is fine.

Thread Participants: 1

Tags for this Thread