"Utilize Ember Data to extract data using a specific serializer

I'm working with an object called "Residence" that consists of various details. I am trying to use the serializer "extractSingle" to establish its relationships when receiving data from the server, but I keep encountering the error message "Unable to get property 'toString' of undefined or null reference". Could someone please point out where I may be going wrong in my approach?

App.Residence = DS.Model.extend({
residence_ID: attr('number'),
house_Number: attr('string'),
street: attr('string'),
city_ID: attr('number'),
state_ID: attr('number'),
zip: attr('string'),
apt: attr('string'),
client_ID: attr('number'),
client: null,
lead: null,
projectDetails: DS.hasMany('projectDetail')
});


App.ResidenceSerializer = DS.WebAPISerializer.extend({
primaryKey: 'residence_ID',

extractSingle: function (store, primaryType, payload) {
    var primaryTypeName = primaryType.typeKey;

    var typeName = primaryTypeName,
        type = store.modelFor(typeName);

    var data = {};
    data[typeName] = payload;
    data.projectDetails = [];

    var normalizedArray = payload.projectDetails.map(function (nav) {
        data.projectDetails.push(nav);
    }, this);
    payload.projectDetails = payload.projectDetails.mapProperty('projectDetailID');

    payload = data;
    return this._super.apply(this, arguments);
},

normalizeHash: {
    projectDetails: function (hash) {
        hash.residence_ID = hash.id;
        hash.id = hash.projectDetailID;
        return hash;
    },
    residence: function (hash) {
        hash.residence_ID = hash.id;
        return hash;
    }
}

});

Here is a snippet of the JSON response retrieved from the server:

   {
   "residence_ID":3532,
   "house_Number":"243",
   "street":"Main St.",
   "city_ID":2,
   "state_ID":33,
   "zip":"11111",
   "apt":"35",
   "client_ID":3598,
   "projectDetails":[{"projectDetailID":4947,"residence_ID":3532"},   {"projectDetailID":4947,"residence_ID":3532}]
   }

Answer №1

execute this._super function with the provided arguments;

It seems like all the effort you put into your work is going to waste as you simply return the super implementation at the end. Instead, you could just return data;.

Additionally, please note that the reference in arguments does not get updated when you assign payload = data;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with custom popup message rendering but the button is unresponsive?

I am currently experiencing an issue with a custom popup that is supposed to display upon form submission. The popup shows up, but there seems to be a problem with the close button functionality. Even though you can click on the X button, it does not close ...

Issue with symbol not functioning on different device

There seems to be a display issue with the ...

The Lenis smooth scrolling feature (GSAP) is not functioning properly

I have encountered an issue with the smooth scrolling feature of gsap causing a delay on my website. This problem is only resolved when I manually go into the browser settings and disable smooth scrolling by navigating to chrome://flags/#smooth-scrolling ...

How can I achieve unique spacing between rows in material-ui grid components?

What is the most effective method for creating spacing between specific rows in a grid using material-ui? Consider the following grid with spacing={0}: GridContainer row1 GridItem GridItem row2 GridItem GridItem row3 GridItem GridItem row4 Gr ...

Would it be frowned upon in JavaScript to use "if (somestring in {'oneoption':false, 'secondoption':false})"?

Is the use of this construct considered a bad practice in JavaScript and could it lead to unexpected behavior? if (e.target.name in {name: '', number: ''}) { // do something } This code checks if the 'name' attribute of an ...

Which variables are accepted in the HTML <script> language?

<script type="text/JavaScript1.2" ... <script type="text/JavaScript" ... Do these script declarations impact the way JavaScript is executed? ...

Guide on incorporating an external JavaScript library into an Angular component for testing purposes

Encountering an issue with a component that utilizes an external JavaScript library called Leader-Line. Every time I attempt to test this component, an error is thrown indicating that the function from the external library is not defined. component file ...

I need to inform users that this application is not accessible on devices with small screens

Showing this app on a small device is not supported, such as when the device width falls between 320px and 480px. ...

What are the reasons for the dynamic exclusion of an element in Angular?

Can someone help me figure out why my data is not being added dynamically using ng-repeat? I have entered the "name" which should be added to the data, but it is not displaying in the UI. You can see the issue in this demo app.controller("studentcntr", ...

unsuccessful transformation using TopoJSON

After successfully installing topojson using the command sudo npm install -g topojson, I encountered issues converting both a shapefile (.shp) and a geojson file to a topojson file. Alexanders-MacBook-Pro:topojson alexander$ geo2topo Parcel11_projected.ge ...

Trigger an Ajax function using a button within a Bootstrap modal

I need to trigger an ajax function after selecting an option from a bootstrap confirmation modal. The modal will appear by calling the remove(parameter) function. Any assistance would be greatly appreciated function remove(parameter){ // $("#remove-mod ...

Update and send back variable on the spot

I'm interested in learning the syntax for creating an inline function that can accept a parameter, perform a simple modification on it, and return it all in a single line. Here's an example: (input) => { input.status = 'complete'; ...

What is the best way to properly pass parameters?

const root = { user: (id) => { console.log("returning object " + JSON.stringify(id.id) + " " + JSON.stringify(storage.select("users", id.id))) return storage.select("users", id.id) } } Struggling to correctly pass the parameter ...

In the production mode, Webpack doesn't compile any code

I recently followed the typescript guide at https://webpack.js.org/guides/typescript/ After running webpack in "production" mode, I noticed that it emitted very minimal output. Below is the code from my src/index.ts file: export function foo() { return ...

How can I monitor an external website using socket.io?

Is there a way to use socket.io to track changes on an external website? I want my server to receive an event whenever that website is updated. For instance: socket.on("newconnectionfromxxxxxxxxxxxxxxx", function (websiteChange) { //websiteChange will ...

Error encountered when trying to access Proxy Object or Object[] in MobX with TypeScript

In my MobX Store, I have a straightforward structure: import { observable, action, makeObservable } from "mobx" import { BoxShadow, ShadowValues } from "./types" import { boxShadow } from "./constants" interface IStore { ...

The Viadeo Social Toolbox seems to be encountering technical difficulties at the moment

I attempted to utilize a Viadeo Social Toolbox, specifically the Viadeo Share Button, but it seems to be malfunctioning in certain browsers? I came across some outdated viadeo share URLs like this: http://www.viadeo.com/shareit/share/?url=${url}&title ...

Generating Angular select options dynamically using ng-repeat

I've been struggling for several days now with ngOptions and ngRepeat. I am trying to create a select option for a people control. The REST service is returning an array as shown below. Despite trying various solutions from Stack Overflow and the Angu ...

What are the steps to refresh the content in a glightbox slider?

I'm currently utilizing Glightbox to set up a gallery that includes descriptions for images. I have a specific request where I want the button text to update on click. However, when the button is clicked and the lightbox reopens, the text on the butto ...

Encountering an error when trying to use variable values for D3 chart instead of static json files, which are working

Our challenge is to retrieve JSON values from a variable (data) and pass them to D3 as JSON input. However, we are encountering an error in Firebug stating "data.links is not defined". The chart displays correctly when we use the JSON values from the sampl ...