PDA

View Full Version : hasOne Relationship



Bleak
17 Mar 2014, 12:39 PM
Hi All,

I have two models



Ext.define('AppConfig.model.Application', {
extend : 'Ext.data.Model',
fields : [ {
name : 'title',
type : 'string'
},
{
name : 'description',
type : 'string'
},

associations:[{type:'hasOne', model:'AppConfig.model.DateRange'}]

]});

Ext.define('AppConfig.model.DateRange', {
extend : 'Ext.data.Model',
fields : [ {
name : 'effective_Date',
type : 'date',
dateFormat: 'Y-m-d'
},
{
name : 'expiry_Date',
type : 'date',
dateFormat: 'Y-m-d'
}]});


The server json looks like this;



{ "returnMessages": null,
"data": {
"title": "First",
"description": "The first application",
"dateRange": {
"effective_Date": "2014-01-01",
"expiry_Date": "2014-12-01"
}
}
}


I have tried so many variations on this, and I do not have a primary/foreign key to work with. Is it possible to use the hasOne association to read in this data?

Zinnia
17 Mar 2014, 10:13 PM
Check the below example , Hope this may help you.
http://jsfiddle.net/el_chief/yrTVn/2/

Bleak
26 Mar 2014, 11:13 AM
I figured out my problem, and of course in the end it was simply. I wasnt including the Models referenced in the associations in the controller that was loading these records. As soon as I added that, everythign was good to go.

Bleak
26 Mar 2014, 11:14 AM
Great example though, thanks Zinnia


Check the below example , Hope this may help you.
http://jsfiddle.net/el_chief/yrTVn/2/