Hi StackOverflow users!
I've got some json data, which should be loaded into a model with three assoctiations. Two of them are okey, but third one would not work.
Here's a json reply from server:
http://pastebin.com/geL16BvL
Main Model:
Ext.define('Invoice', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'invoice_id', type: 'string'},
{name: 'invoice_date', type: 'date', dateFormat: 'time'},
{name: 'invoice_due_date', type: 'date', dateFormat: 'time'},
{name: 'invoice_year_index', type: 'int'},
{name: 'invoice_total', type: 'number'},
{name: 'invoice_vat', type: 'number'},
{name: 'invoice_delivery', type: 'number'},
{name: 'invoice_total_cost', type: 'number'},
{name: 'invoice_payment_method', type: 'string'},
{name: 'invoice_status', type: 'string'},
{name: 'invoice_discount', type: 'number'},
{name: 'invoice_discount_type', type: 'string'},
{name: 'invoice_fixed_charges', type: 'number'},
{name: 'invoice_currency_code', type: 'string'},
{name: 'invoice_currency_symbol', type: 'string'},
{name: 'localization_data_source', type: 'string', mapping: 'data_source.data_source_name'}
],
associations: [
{model: 'Contractor', name: 'contractor', type: 'hasOne'},
{model: 'SalesRepresentative', name: 'salesRepresentative', type: 'hasOne', associationKey: 'salesRepresentative'},
{model: 'InvoiceItem', name: 'invoiceItems', type: 'hasMany'}
]
});
Two working:
Ext.define('InvoiceItem', {
extend: 'Ext.data.Model',
belongsTo: 'Invoice',
fields: [
{name: 'id', type: 'int'},
{name: 'invoice_id', type: 'string'},
{name: 'item_variation_id', type: 'string'},
{name: 'item_quantity', type: 'number'},
{name: 'item_name', type: 'string'},
{name: 'item_price', type: 'number'},
{name: 'item_value', type: 'number'},
{name: 'item_position_vat', type: 'number'},
{name: 'item_vat', type: 'number'},
{name: 'item_tax', type: 'number'},
{name: 'item_category_name', type: 'string'},
{name: 'item_discount', type: 'number'},
{name: 'item_price_before_discount', type: 'number'}
]
});
Ext.define('Contractor', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int'},
{name: 'contractor_id', type: 'string'},
{name: 'contractor_email', type: 'string'},
{name: 'contractor_status', type: 'string'},
{name: 'contractor_registered', type: 'date', dateFormat: 'time'},
{name: 'contractor_name', type: 'string'},
{name: 'contractor_company', type: 'string'},
{name: 'contractor_company_vat_no', type: 'string'},
{name: 'contractor_phone', type: 'string'},
{name: 'contractor_address', type: 'string'},
{name: 'contractor_city', type: 'string'},
{name: 'contractor_postcode', type: 'string'},
{name: 'contractor_country', type: 'string'}
]
});
And Third one - SalesRepresentative:
Ext.define('SalesRepresentative', {
extend: 'Ext.data.Model',
belongsTo: 'Invoice',
fields: [
{name: 'id', type: 'int'},
{name: 'representative_id', type: 'string'},
{name: 'representative_name', type: 'string'},
{name: 'representative_email', type: 'string'}
]
});
When I access Contractor or store with InvoiceDetails anything works really well. But when I try to access SalesRepresentative for example via:
Ext.getStore('invoicesStore').getAt(0).getSalesRepresentative()
I'm receiving
"TypeError: url is
return url + (url.indexOf('?') === -1 ? '?' : '&') + string;"
I'm pretty sure that somethings wrong with relations, but I can't find way to make it work.
See Question&Answers more detail:
os