PDA

View Full Version : HasMany associations not loaded from ArrayStore



cyclops
5 May 2015, 5:08 AM
I've been reading some posts about the same issue but cannot get my code working using the recommendations posted there.
I am using an ArrayStore for the parent model, loaded with json data by request. The data received from my service looks like this:


{
"id": "223ba456-1f85-e411-9c92-00155df43d02",
"name": "1",
"accountingTypeCode": "d5c1a820-821c-df11-b323-00155df40b02",
"accountingTypeName": "Berechnet",
"agencyCommission": 0,
"bleed": 0,
"canceledProductId": null,
"closureDiscount": 0,
"colorId": "745849c2-08f7-df11-b0a5-00155df41007",
"currencyId": "08fbc6b1-d228-dd11-9978-00155df41007",
"currencySymbol": "€",
"discountInfo": 0.0000,
"endDate": null,
"externalOrderNumber": null,
"formatId": null,
"formatName": null,
"info": null,
"insertionTypeId": "9fd5fb8c-8963-df11-a5c9-00155df41007",
"insertionTypeName": "Beihefter",
"issueId": "73b94bf1-99fb-e111-a89f-00155df43d18",
"issueName": "01\/2015",
"motive": null,
"netTotal": 16830.0000,
"number": 10,
"orderId": "203ba456-1f85-e411-9c92-00155df43d02",
"orderManagementTypeId": "cb34daf5-1ac3-e011-8db3-00155df41007",
"orderManagementTypeName": "Normal",
"pagecountWeight": 25,
"period": null,
"placement": null,
"price": 187.0000,
"priceType": 2,
"priceZoneId": "93c1ac02-2f3b-e311-9d9f-00155df43d05",
"priceZoneName": "Preiszone 2",
"productType": "AdSpecial",
"publicationFormatId": null,
"publicationFormatName": null,
"publicationId": "d4170059-8a63-df11-a5c9-00155df41007",
"publicationName": "GALA",
"publicationSectionId": "fbb5bfd6-0fa5-e011-8db3-00155df41007",
"publicationSectionName": "Ohne Ressort",
"quantity": 9,
"specialDiscount1": 0,
"specialDiscount1Name": "Sonderrabatt 1",
"specialDiscount2": 0,
"specialDiscount2Name": "Sonderrabatt 2",
"specialDiscount3": 0,
"specialDiscount3Name": null,
"splitRunId": "eb81e8e9-102d-e011-b0a5-00155df41007",
"splitRunName": "Inland inkl. Abo",
"splitRunNames": "Abo Inland - Nielsen 1, Abo Ausland - Nielsen 1",
"splitruns": [
{
"id": "233ba456-1f85-e411-9c92-00155df43d02",
"name": "Abo Inland - Nielsen 1",
"numberOfCopies": 9000,
"productId": "223ba456-1f85-e411-9c92-00155df43d02",
"splitRunId": "97a3cda5-9ea8-e011-8db3-00155df41007",
"splitRunName": "Nielsen 1",
"spreadingId": "ed361c40-9ea8-e011-8db3-00155df41007",
"spreadingName": "Abo Inland"
},
{
"id": "243ba456-1f85-e411-9c92-00155df43d02",
"name": "Abo Ausland - Nielsen 1",
"numberOfCopies": 0,
"productId": "223ba456-1f85-e411-9c92-00155df43d02",
"splitRunId": "97a3cda5-9ea8-e011-8db3-00155df41007",
"splitRunName": "Nielsen 1",
"spreadingId": "19d4df7b-9ea8-e011-8db3-00155df41007",
"spreadingName": "Abo Ausland"
}
],
"startDate": "\/Date(1418770800000)\/",
"statusCode": 100000000,
"statusName": null,
"surchargeType": null,
"surcharges": null,
"total": 16830.0000,
"unit": 1000,
"useAvgPrices": 0,
"workflowStatus": null
}

The model and store declarations are:


Ext.define('Guj.orderfastentry.model.OrderProduct', {
extend: 'Ext.data.Model',
idProperty: 'id',
requires: [
'Guj.orderfastentry.model.Surcharge',
'Guj.orderfastentry.model.SplitRun'
],
fields: [
{ name: 'orderId', type: 'string' }, // Guid des Auftrags aus CRM
{ name: 'externalOrderNumber', type: 'string' }, // VM AB-Nr.
{ name: 'id', type: 'string' }, // Guid der Position aus CRM
{ name: 'name', type: 'string' }, // Name (primäres Attribut aus CRM)
{ name: 'productType', type: 'string' }, // Positionsart (Print/AdSpecial/Digital)
{ name: 'accountingTypeCode', type: 'string' }, // Buchungskennzeichen (Id)
{ name: 'accountingTypeName', type: 'string' }, // BKZ-Name
{ name: 'discountInfo', type: 'float' }, // Kumulation der Zu-/Abschläge
{ name: 'info', type: 'string' }, // Bemerkung
{ name: 'issueId', type: 'string' }, // Ausgabe (Lookup)
{ name: 'issueName', type: 'string' },
{ name: 'startDate', type: 'date', dateFormat: 'MS' }, // Beginn
{ name: 'endDate', type: 'date', dateFormat: 'MS' }, // Ende
{ name: 'insertionTypeId', type: 'string' }, // Insertionsart (Lookup)
{ name: 'insertionTypeName', type: 'string' },
{ name: 'publicationId', type: 'string' }, // Werbeträger (Lookup)
{ name: 'publicationName', type: 'string' },
{ name: 'publicationSectionId', type: 'string' }, // Ressort (Lookup)
{ name: 'publicationSectionName', type: 'string' },
{ name: 'formatId', type: 'string' }, // Format (Lookup)
{ name: 'formatName', type: 'string' },
{ name: 'publicationFormatId', type: 'string' }, // Format (Lookup)
{ name: 'publicationFormatName', type: 'string' },
{ name: 'placement', type: 'string' }, // Platzierung (Freitext)
{ name: 'orderManagementTypeId', type: 'string' }, // Dispoart (Lookup)
{ name: 'orderManagementTypeName', type: 'string' },
{ name: 'splitRunId', type: 'string' }, // Teilbelegung (Lookup nur über CRM-Form editierbar)
{ name: 'colorId', type: 'string' }, // Farbigkeit (Lookup nur über CRM-Form editierbar)
{ name: 'quantity', type: 'int' }, // Auflage (AdSpecial)
{ name: 'unit', type: 'int' }, // Mengeneinheit
{ name: 'number', type: 'int' }, // Menge
{ name: 'pagecountWeight', type: 'int' }, // Seiten/Gewicht (AdSpecial)
{ name: 'priceType', type: 'int' }, // Preistyp
{ name: 'price', type: 'float' },
{ name: 'splitRunId', type: 'string' },
{ name: 'splitRunName', type: 'string' },
{ name: 'splitRunNames', type: 'string' },
{ name: 'priceZoneId', type: 'string' },
{ name: 'priceZoneName', type: 'string' },
{ name: 'total', type: 'float' }, // Kundenbrutto
{ name: 'closureDiscount', type: 'float' }, // Abschlussrabatt (%)
{ name: 'specialDiscount1', type: 'float' }, // Sonderrabatte (%)
{ name: 'specialDiscount2', type: 'float' },
{ name: 'specialDiscount3', type: 'float' },
{ name: 'specialDiscount1Name', type: 'string' }, // Sonderrabatte (%)
{ name: 'specialDiscount2Name', type: 'string' },
{ name: 'specialDiscount3Name', type: 'string' },
{ name: 'agencyCommission', type: 'float' }, // Agenturprovision (%)
{ name: 'netTotal', type: 'float' }, // Agenturnetto
{ name: 'statusCode', type: 'string' }, // Positionsstatus
{ name: 'statusName', type: 'string' },
{ name: 'bleed', type: 'int' }, // Anschnitt 0/1 (nur über CRM-Formular editierbar)
{ name: 'useAvgPrices', type: 'int' }, // Durchschnittspreise verwenden (nur über CRM-Formular editierbar)
{ name: 'motive', type: 'string' }, // Motiv (Freitext)
{ name: 'recordStatus', type: 'int' }, // Bearbeitungsstatus in Grid (intern, nicht persistiert im CRM)
{ name: 'statusMessage', type: 'string' }, // Statushinweis für Validierungs-/Speicherfehler (intern, nicht persistiert im CRM)
{ name: 'currencyId', type: 'string' }, // Währung
{ name: 'currencySymbol', type: 'string' }, // Währungskürzel der TransactionCurrency
{ name: 'surchargeType', type: 'string' }, // Info, ob Zu-/Abschläge definiert sind (cf. SurchargeTypes)
{ name: 'workflowStatus', type: 'string' } // Aktueller Workflow-Status für Digital-Positionen
],
hasMany: [
{ model: 'Guj.orderfastentry.model.Surcharge', name: 'surcharges', associationKey: 'surcharges' },
{ model: 'Guj.orderfastentry.model.SplitRun', name: 'splitruns', associationKey: 'splitruns', autoLoad: true }
],
proxy: {
type: 'memory',
reader: {
type: 'json'
}
}
});

Ext.define('Guj.orderfastentry.model.Surcharge', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{ name: 'id', type: 'string' },
{ name: 'type', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'currencySymbol', type: 'string' },
{ name: 'value', type: 'float' },
{ name: 'percentage', type: 'float' }
],
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'surcharges'
}
}
});

Ext.define('Guj.orderfastentry.model.SplitRun', {
extend: 'Ext.data.Model',
idProperty: 'id',
fields: [
{ name: 'id', type: 'string' },
{ name: 'name', type: 'string' },
{ name: 'splitRunId', type: 'string' },
{ name: 'spreadingId', type: 'string' },
{ name: 'numberOfCopies', type: 'int' }
],
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'splitruns'
}
}
});

Ext.define('Guj.orderfastentry.store.OrderProductsAdSpecial', {
extend: 'Ext.data.ArrayStore',
model: 'Guj.orderfastentry.model.OrderProduct',
proxy: {
type: 'memory',
reader: {
type: 'json'
}
}
});


When accessing the surcharges-Store via record.splitruns() on the model instance it is present but empty...

Loading the data via record.splitruns().loadData(record.raw.splitruns) works though. But I assume it's not intended to be that way..

ExtJS Version used is 4.2.2

Any suggestions? I'm lost! :((

mitchellsimoens
11 May 2015, 7:49 AM
Couple questions:

1. Why are you using Ext.data.ArrayStore and not Ext.data.Store?
2. I see you are using memory proxy, how are you loading data into the store?

cyclops
11 May 2015, 7:58 AM
1. Well, the data I load into the store is an array of objects (according to the first code sample) so I thought it appropriate. What's the benefit of using just store? The fields are being loaded just fine but the association stores remain empty.

2. I got that from another blog-post but it didn't help though... I'm using loadData() on the 'master'-store (Guj.orderfastentry.store.OrderProductsAdSpecial) which is bound to a grid.

mitchellsimoens
11 May 2015, 9:10 AM
Associations are only parsed via a remote call that is run through the reader. Local data thrown into the store will not be parsed by the reader.

cyclops
11 May 2015, 9:15 AM
OK thanks for that, so my way of loading the association store on demand is the only way besides having my webservice being called directly from the store?

mitchellsimoens
11 May 2015, 9:17 AM
Remote loading is how it was designed. You can hack the framework to get it to work locally but that is not officially supported.