2012-11-20 4 views
0

그래서 Sencha ExtJs 4.1 Associations을 사용하는 데 문제가 있습니다.Sencha ExtJS 연관 POST가 잘못 되었습니까?

{ 
    "postTemplate": 1, 
    "id": 0, 
    "name": "foo" 
} 
: 문제는 내가 이런 POST를 얻고 있다는 것입니다

Ext.define('Tpl.store.Users', { 
    extend: 'Ext.data.Store', 
    model: 'Tpl.model.User', 
    autoLoad: true, 
    proxy: { 
     type: 'rest', 
     url: '../users', 
     reader: { 
      type: 'json', 
      root: '' 
     }, 
     writer: { 
      type: 'json' 
     } 
    } 
}); 

Ext.define('Tpl.store.PostTemplate', { 
    extend: 'Ext.data.Store', 
    model: 'Tpl.model.PostTemplate', 
    autoLoad: true, 
    proxy: { 
     type: 'rest', 
     //appendId: true, 
     url: '../postTemplates/', 
     reader: { 
      type: 'json', 
      root: '' 
     }, 
     writer: { 
      type: 'json' 
     } 
    } 
}); 

모델

Ext.define('Tpl.model.User', { 
    extend: 'Ext.data.Model', 
    requires: ['Tpl.model.PostTemplate'], 
    fields: [ 
     { name: 'id', type: 'int' }, 
     { name: 'name', type: 'string' }, 
     { name: 'postTemplate', type: 'int' } 
    ], 
    associations: [ 
     { type: 'belongsTo', name: 'postTemplate', model:'Tpl.model.PostTemplate', associationKey: 'postTemplate', primaryKey: 'id', foreignKey: 'postTemplate' } 
    ] 
}); 

and 

Ext.define('Tpl.model.PostTemplate', { 
    extend: 'Ext.data.Model', 

    fields: [ 
     { name: 'id', type: 'int' }, 
     { name: 'blah', type: 'string' } 
    ], 

    associations: [ 
     { type: 'hasMany', model: 'Tpl.model.User' } 
    ] 

}); 

상점 :

내가 좋아하는 뭔가를

는하지만이 같은 POST 필요

{ 
    "postTemplate": { 
     "id": 1, 
     "blah": "foo" 
    }, 
    "id": 0, 
    "name": "bar" 
} 

또한, "setPostTemplate"와 같은 평가자 기능이 존재하지 않습니다 나는이 자동으로 생성한다고 생각합니다.

이미 같은 뭔가 시도 "record.data.postTemplate = (...)"하지만 내가 execption을 던지는 무한 루프 ...

누군가가 조언을 주실 수 있어요? 또한, 당신이 대답을 위해 유용 할 수있는 다른 것을 필요로한다면 저에게 알려주십시오.

감사합니다.

답변

1

사용 가능한 즉시 연결된 개체는 예상대로 서버에 직렬화되지 않습니다. 이 문제는 여러 번 제기되었습니다. 가장 좋은 것은이 스레드를 수행 할 수 있습니다 다음 JSON 작가 클래스에 getRecordData를 오버라이드 (override)에 대한

http://www.sencha.com/forum/showthread.php?141957-Saving-objects-that-are-linked-hasMany-relation-with-a-single-Store

이 스레드 회담.

+0

대단히 감사합니다. @dbrin !!! –