I have an Ember model set up with mirage and a serializer. When I added some new fields to the model, they never get populated despite being in the payload:
serializers/application.js
....
normalizeArrayResponse(store, primaryModelClass, payload, id, requestType) {
const payloadTemp = {};
const rootKey = Ember.String.pluralize(primaryModelClass.modelName);
payload.properties.forEach((property, index) => {
// payload[index].featured_image = property["_embedded"]["wp:featuredmedia"]
payload.properties[index].featured_image = property["embedded"]["wp:featuredmedia"]
});
//payloadTemp[rootKey] = payload;
return this._super(store, primaryModelClass, payload, id, requestType);
},
models/property.js
export default Model.extend({
date: attr('date'),
slug: attr('string'),
title: attr(),
excerpt: attr(),
department: attr('string'),
latitude: attr('string'),
address_street: attr('string'),
address_two: attr('string'),
address_three: attr('string'),
address_four: attr('string'),
address_postcode: attr('string'),
features: attr('string'),
feature_1: attr('string'), //new
feature_2: attr('string'), //new
feature_3: attr('string'), //new
feature_4: attr('string'), //new
longitude: attr('string'),
price: attr('string'),
price_formatted: attr('string'),
currency: attr('string'),
tenure: attr('string'),
property_type: attr('string'), //new
bedrooms: attr('string'),
bathrooms: attr('string'),
parking: attr('string'),
reception_rooms: attr('string'),
featured_image: attr()
});
Example fixture:
"id": 20829,
"date": "2017-05-22T16:31:42",
"date_gmt": "2017-05-22T16:31:42",
"guid": {
"rendered": "http://ift.tt/2rjPPeC"
},
"modified": "2017-05-25T16:00:04",
"modified_gmt": "2017-05-25T16:00:04",
"slug": "goldstone-crescent-dunstable",
"status": "publish",
"type": "property",
"link": "http://ift.tt/2rjPPeC",
"title": {
"rendered": "Goldstone 2 Crescent DUNSTABLE"
},
"excerpt": {
"rendered": "<p>NO UPPER CHAIN – A THREE BEDROOM EXTENDED SEMI DETACHED HOUSE LOCATED TO THE EAST OF TOWN THAT FEATURES, CLOAK/SHOWER ROOM, UTILITY ROOM/STUDY, LANDSCAPED GARDENS AND GARAGE WITH AMPLE PARKING.</p>\n",
"protected": false
},
"template": "",
"department": "residential-sales",
"address_street": "",
"address_two": "",
"address_three": "Dunstable",
"address_four": "",
"address_postcode": "LU5 4QU",
"latitude": "51.8936687",
"longitude": "-0.5047035",
"price": "325000.00",
"price_formatted": "£325,000",
"currency": "",
"price_qualifier": "",
"sale_by": "",
"tenure": "Freehold",
"deposit": "",
"furnished": "",
"available_date": "",
"bedrooms": "3",
"bathrooms": "",
"reception_rooms": "1",
"property_type": "Semi-Detached House",
"parking": "Garage and Driveway, Parking For 2 Cars",
"outside_space": "",
"featured": "",
"availability": "For Sale",
"marketing_flags": "",
"features": [
"NO UPPER CHAIN",
"A THREE BEDROOM EXTENDED",
"SEMI DETACHED HOUSE",
"LOCATED TO THE EAST OF TOWN",
"CLOAK/SHOWER ROOM",
"UTILITY ROOM/STUDY",
"LANDSCAPED GARDENS",
"GARAGE WITH AMPLE PARKING",
"GAS FIRED CENTRAL HEATING",
"DOUBLE GLAZING"
],
"feature_1": "A THREE BEDROOM EXTENDED",
"feature_2": "SEMI DETACHED HOUSE",
"feature_3": "LOCATED TO THE EAST OF TOWN",
"feature_4": "CLOAK/SHOWER ROOM",
"description": "<p class=\"room\">ACCOMMODATION COMPRISES: Etended entrance hall, utility/study, cloak/shower room, large kitchen/dining room, large lounge to the rear of the property overlooking landscaped private garden, large landing with three generous bedrooms and bathroom, driveway, ample parking and gardens.\n </p>\n ",
"office": {
"name": "Dunstable Office",
"address": "20 West Street Dunstable Bedfordshire, LU6 1SX",
"telephone_number": "01582 661112",
"email_address": "sales@robinsons-estates.co.uk"
},
Within the normalizeArrayResponse
function, checking for property.property_type
exists within the payload.properties.forEach
loop but then once it becomes a record the fields that were added after the model was first created (highlighted with //new
are always undefined.
Aucun commentaire:
Enregistrer un commentaire