PDA

View Full Version : about model relationship



lenxeon
27 Aug 2013, 5:35 PM
my json data


{
"version": 0,
"id": 1,
"title": "?????????????????",
"tags": [
{
"version": 0,
"id": 11,
"keyword": "??",
"resources": [],
"delete": 0,
"create_date": "2013-06-08 02:51:21",
"book_num": 0,
"article_num": 0,
"bilingual_num": 0
}
],
"preview": "http://mat1.qq.com/book/s/200910/15/10/125557467862047.jpg",
"summary": "??????????CEO???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????  ???????????????????????????????????????????????……",
"sort": {
"version": 0,
"id": 1,
"name": "??",
"cid": [],
"resources": [],
"delete": 0,
"create_date": "2013-08-28 09:32:32",
"book_num": 0
},
"seo": {
"version": 0,
"id": 0,
"title": "??",
"keywords": "???",
"description": "??",
"delete": 0,
"create_date": "2013-08-28 09:32:32"
},
"comments": [],
"score": 0,
"user": "",
"url": "http://book.qq.com/s/book/0/18/18526/index.shtml",
"publish": {
"version": 0,
"id": 1,
"name": "???????",
"delete": 0,
"create_date": "2013-08-28 09:32:32"
},
"copyright": 0,
"volumes": [],
"price": 0,
"author": {
"version": 0,
"id": 1,
"name": "??????",
"mobile": "",
"email": "",
"qq": "",
"msn": "",
"addr": "",
"delete": 0,
"create_date": "2013-08-28 09:32:32"
},
"finish": 0,
"free": 0,
"online": 0,
"delete": 0,
"create_date": "2012-11-12 01:42:27",
"resource_type": "BOOK",
"publish_date": "2013-08-28 09:32:32",
"vir_price": 0
}


my model
book


Ext.define('App.model.resource.Book', {
extend: 'App.model.resource.Resource',
id: 'Book',
idProperty: 'id',
requires: ["App.model.resource.Author"],


fields: [{
name: 'id',
type: 'int',
mapping: 'id'
}, {
name: 'url',
type: 'string',
mapping: 'url'
}, {
name: 'publish_date',
type: 'date',
format: 'Y-m-d',
mapping: 'publish_date'
}, {
name: 'finish',
type: 'int',
mapping: 'finish'
}, {
name: 'online',
type: 'int',
mapping: 'online'
}, {
name: 'free',
type: 'int',
mapping: 'free'
}, {
name: 'copyright',
type: 'int',
mapping: 'copyright'
}, {
name: 'vir_price',
type: 'string',
mapping: 'vir_price'
}, {
name: 'price',
type: 'int',
mapping: 'price'
}],
associations: [{
type: 'belongsTo',
model: "Author",
primaryKey: "id",
foreignKey: "author"
}]
});


author


Ext.define('App.model.resource.Author', {
extend: 'App.model.resource.Resource',
fields: [{
name: 'id',
type: 'int',
mapping: 'id'
}, {
name: 'name',
type: 'string',
mapping: 'name'
}, {
name: 'mobile',
type: 'string',
mapping: 'mobile'
}, {
name: 'email',
type: 'string',
mapping: 'email'
}, {
name: 'qq',
type: 'string',
mapping: 'qq'
}, {
name: 'msn',
type: 'string',
mapping: 'msn'
}, {
name: 'addr',
type: 'string',
mapping: 'addr'
}, {
name: 'delete',
type: 'int',
mapping: 'delete'
}, {
name: 'create_date',
type: 'string',
mapping: 'create_date'
}, {
name: 'version',
type: 'int',
mapping: 'version'
}]
});



my grid panel


this.columns = [{
text: 'ID',
width: 60,
dataIndex: 'id'
}, {
text: '??',
width: 300,
dataIndex: 'title'
}, {
text: '??',
width: 150,
dataIndex: 'author.name'
}, {



i want use author.name, but it can not work.

dawesi
27 Aug 2013, 9:53 PM
I'm assuming from your data there is only ever one author, so why not just add this as a column in your book model and get rid of your author model?



{ name: 'authorname', mapping: 'author.name' }