hasMany 관계를 설정하려고하고 모든 요청 모델에서 관련된 모든 모델을 단일 요청으로로드하려고합니다. 하지만 그것은 상속 된 "hasMany"관계와 작동하지 않는 것 같습니다. 모든 관계와 필드를 정의하는 BaseModel과로드 할 프록시를 정의하는 "일반"모델이 있습니다.ExtJS 6 상속 hasMany 관계 중첩 된 로딩
이 내 (관련) 모델입니다 : 이것은 내 서버의 응답입니다
Ext.define('MyApp.model.BaseUser', {
"extend": "Ext.data.Model",
"uses": [
"MyApp.model.UserEmail",
"MyApp.model.Account"
],
"fields": [
{
"name": "name"
},
{
"name": "accountId",
"reference": {
"type": "MyApp.model.Account",
"role": "account",
"getterName": "getAccount",
"setterName": "setAccount",
"unique": true
}
}
]
"hasMany": [
{
"name": "emails",
"model": "MyApp.model.UserEmail"
}
],
});
Ext.define('MyApp.model.User', {
extend: "MyApp.model.BaseUser",
proxy: {
type: 'rest',
url : '/api/user',
reader: {
type: 'json',
rootProperty: 'data',
}
}
});
Ext.define('MyApp.model.UserEmail', {
extend: 'Ext.data.Model',
"fields": [
{
"name": "id",
"type": "int"
},
{
"name": "email",
"type": "string"
},
],
proxy: {
type: 'rest',
url : '/api/user/email',
reader: {
type: 'json',
rootProperty: 'data',
}
}
});
// MyApp.model.Account looks like MyApp.model.UserEmail
: "계정"관계는 "정상적인"사용자 모델에 작동하고 나는 액세스 할 수 있습니다
{
data: [
{
name: 'User Foo'
accountId: 50
account: {
id: 50,
balance: 0
},
emails: [
{
id: 70,
email: '[email protected]'
}
]
}
]
}
예상대로 자동 생성 된 user.getAccount() 메소드를 통해.
는 이제 자동 생성 방법과 사용자의 이메일에 액세스하려고 :// user is of 'MyApp.model.User'
user.emails(); // store
user.emails().first(); // null
user.emails().count(); // 0
"이메일"-relation 모델 내 사용자 모델에로드되지 않은 것으로 보인다. 내가 올바른 방법으로 접근하고 있는가? user.data.emails를 통해 액세스 할 수 있습니다. 그러나 이것은 UserEmail-Objects가 아닌 일반 개체의 배열입니다.
아무도 나에게 조언을 해줄 수 있습니까? 중첩 된로드가 키없는 연결로 지원됩니까? Clearified 내가, 표준 무엇 :
종류 안부, 는
편집을 czed.
답장을 보내 주셔서 감사합니다. 내가 알기로는 내 모델이 정확하지 않았다. 관계를 기본 모델로 정의하고 확장했습니다. 그게 문제인 것처럼 보입니다. 내 게시물을 수정하고 이것을 정리했습니다. 그 죄송합니다 –