Troubleshooting issues with ember-data's belongsTo relationship

I am facing an issue with the model I have:

Whenever I make a call to this.store.find('history');

A request is sent to http:://www.example.com/api/histories/ and I receive the following JSON response:

{
   "tracks":[
      {
         "id":83,
         "title":"Untitled",
         "length":148,
         "artist_ids":[

         ],
         "album_ids":[

         ]
      },
      {
         "id":85,
         "title":"You want it",
         "length":262,
         "artist_ids":[

         ],
         "album_ids":[

         ]
      },
      ...
   ],
   "albums":[

   ],
   "artists":[

   ],
   "histories":[
      {
         "id":1382220844,
         "time_played":"2013-10-20 00:14:04",
         "user_id":null,
         "track_id":83
      },
      ...
   ]
}

After fetching the data, both Store.History and Store.Track records are successfully stored.

However, upon inspecting a record from Store.History, the "track" attribute appears to be null.

I have verified that the Store.Track records contain the same IDs as those in the JSON response.

For reference, here are my models:

var attr = DS.attr,
    belongsTo = DS.belongsTo,
    hasMany = DS.hasMany;

Shoutzor.Album = DS.Model.extend({
    ...
});

Shoutzor.Artist = DS.Model.extend({
    ...
});

Shoutzor.User = DS.Model.extend({
    ...
});

Shoutzor.Track = DS.Model.extend({
    ...
});

Shoutzor.History = DS.Model.extend({
    ...
});

If anyone can provide assistance on this matter, it would be highly appreciated.

Answer โ„–1

To ensure compatibility with ember data 1.0, your history json should follow this format: https://github.com/emberjs/data/blob/master/TRANSITION.md

{
     "id":1382217657,
     "time_played":"2013-10-19 23:20:57",
     "user":null,
     "track":84
  },

Remember to remove the "_id" field from your JSON.

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

The knockout click event isn't functioning properly for a table generated by ko.computed

My goal is to connect a table to a drop-down menu. Here are the key points of what I'm trying to achieve: The drop-down should list MENUs. Each MENU can have multiple MODULES associated with it, which will be displayed in the table based on the ...

What is the procedure for passing arguments to Google signIn in a NextJS backend?

I am currently working on implementing a role-based Google sign-in feature in a Next.js 13 app using next-auth. This setup involves calling two different tables to create users based on their assigned roles. For the database, I am utilizing mongodb/mongoo ...

Having trouble deciding between JSON, XML, or using a database?

As I work on developing an app that involves sending an id and receiving a JSON node from PHP, I am considering the best approach for storing my data. Should I keep it as a static PHP array as shown in the code below, or should I save the data to an exte ...

Unable to retrieve data from file input using jQuery due to undefined property "get(0).files"

I am facing an issue with retrieving file data in jQuery AJAX call from a file input on an ASP.NET view page when clicking a button. HTML <table> <td style="text-align:left"> <input type="file" id="AttachmenteUploadFile" name="Attachme ...

Transform data into JSON format using AJAX in CodeIgniter

I am having trouble with converting json code in CodeIgniter for pagination. I am using ajax to control the data conversion to json and sending it to the view. Can someone please explain how to do this? In the controller, instead of using a foreach loop, ...

Steps to obtain a Json Response post successful data storage in ASP.Net

After creating data, how can I receive a response? I want the response to be displayed when it is saved, maybe in a message box. Is this possible? Below is my controller code for saving: [HttpPost] [ValidateAntiForgeryToken] public async System.T ...

`Proliferating values through constantly changing addition`

I am facing an issue with my code that involves 3 input fields: <div class="row"> <input onblur="calc_basic_amount();" id="rate_basic"></input> <input onblur="calc_basic_amount();" id="qty_b ...

What could be the reason for a querySelector returning null in a Nextjs/React application even after the document has been fully loaded?

I am currently utilizing the Observer API to track changes. My objective is to locate the div element with the id of plTable, but it keeps returning as null. I initially suspected that this was due to the fact that the document had not finished loading, ...

Search for particular words using pandas

I wanted to figure out a method to Success! Step 1) possibly tally all instances of specific text (e.g "็ฅž" or "ไปๆ•™") in a single json or csv file. import pandas as pd pd.options.display.max_rows = 10000 # read the file df = pd.read_csv("/mypath/resu ...

How can you utilize jQuery to iterate through nested JSON and retrieve a specific matching index?

In the scenario where I have a nested JSON object like this: var library = { "Gold Rush": { "slides": ["Slide 1 Text","Slide 2 Text","Slide 3 Text","Slide 4 Text"], "bgs":["<img src='1.jpg' />","","<img src='2.j ...

Incomplete header data in Angular $resource GET request

Currently, I am working with Ionic 1.3 and Angular 1.5. My goal is to retrieve some header properties from my response. The code snippet I am using looks something like this: factory('Service', function($resource, API_SETTINGS, JsonData) { re ...

Strange JSON format detected when consuming the Python Hug REST API in a .NET environment

When using a Hug REST endpoint to consume JSON in .net, there are issues with embedded characters that I am facing. See the example below for a complete failure. Any assistance would be greatly appreciated. Python @hug.post('/test') def test(re ...

Tips for accessing and storing a particular value from a JSON object array in a variable

I have some code that retrieves data from my database. The output is in the form of a list: results = [(2, '4'), (2, '17'), (3, '65'), (1, '54'), (2, '14'),...] I aim to convert this list into a JSON obj ...

I'm puzzled by the error message stating that '<MODULE>' is declared locally but not exported

I am currently working with a TypeScript file that exports a function for sending emails using AWS SES. //ses.tsx let sendEmail = (args: sendmailParamsType) => { let params = { //here I retrieve the parameters from args and proceed to send the e ...

Is it possible to use Javascript to retrieve a variable from a remote PHP file?

I am trying to retrieve a variable from a remote PHP file using JavaScript in my phonegap application. The same origin policy doesn't apply here, so I believe I need to use JSON/AJAX for this task. However, I have been unable to find any tutorials tha ...

Include a class above the specified element; for instance, apply the class "act" to the "<ul>" element preceding the "li.item1"

Hello there! I need some assistance, kinda like the example here Add class and insert before div. However, what I really want to do is add the class "act" to a class above that matches the one below: Here's how it currently looks: <ul> ...

What causes a Next.js App to crash when a prop is not defined in destructuring code?

Let me share the issue I am facing. I have developed a custom Context API wrapper to handle all my data. However, there is this docType property that may not always be defined or may not exist at times. When I destructure it in this way: const { docType } ...

Retrieve an array from a JSON object by accessing the corresponding key/value pair using the utility library underscore

I have a dataset in JSON format (as shown below) and I am attempting to use the _.where method to extract specific values from within the dataset. JSON File "data": [{ "singles_ranking": [116], "matches_lost": ["90"], "singles_high_rank": [79 ...

Ensuring the accurate usage of key-value pairs in a returned object through type-checking

After generating a type definition for possible response bodies, I am looking to create a function that returns objects shaped as { code, body }, which are validated against the typing provided. My current solution looks like this: type Codes<Bodies> ...

What is the best way to ensure that messages stay saved in my app for an extended

I am looking for a way to store messages sent through my small messaging app in a persistent manner. Currently, the messages are transferred from the front-end to a Node, Socket.io, and Express back-end. A friend recommended using Enmaps (), but unfortuna ...