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

Manipulating an Array of Objects based on conditions in Angular 8

I have received an array of objects from an API response and I need to create a function that manipulates the data by enabling or disabling a flag based on certain conditions. API Response const data = [ { "subfamily": "Hair ...

Error Alert: Invalid Hook Call detected while using the useSelector hook within a Functional Component

I am encountering an error Error: Invalid hook call. Hooks can only be called inside of the body of a function component. The versions of React and the renderer (such as React DOM) might not match There could be violations of the Rules of Hooks Multiple ...

Utilize express.static to showcase and fetch HTML content before serving JavaScript files

I'm having trouble getting my home.html file to display properly on the browser when I'm using express.static. Here is how my directory and file layout are structured: dir main -server.js dir subMain dir routing -routes.js ...

Creating Custom Filters in Angular using Functions

Attempting to filter ng-repeat using a function instead of an actual filter has presented some challenges. The code snippet below demonstrates the attempt: <tr ng-repeat="(key, value) in dataObj| filter:dataFilter"> The intention is to define dataF ...

The map function is mistakenly returning double the amount of the object it should be returning

My program is fetching data from an API, but when I try to map the array for interesting data, it downloads the same object multiple times. For the first search, it downloads the object twice and for subsequent searches, it downloads the object six times. ...

Shutting down browser with WebdriverIO and launching a new one

I am facing a challenge in my application testing process. I need to simulate a scenario where I close the browser and session, then open a new browser and session to check if the previously entered data can be successfully recalled by passing certain laun ...

Is there a method to ensure that the window event always gets triggered before any other events?

Is there a way to make the window event trigger first when clicking on #myDiv? (function ($, w, d) { $(d).ready(function () { $(w).click(function() { alert('window has been clicked'); }); $('#myDiv').cl ...

Vue failing to update when a computed prop changes

As I work with the Vue composition API in one of my components, I encountered an issue where a component doesn't display the correct rendered value when a computed property changes. Strangely, when I directly pass the prop to the component's rend ...

Step by step guide on rotating a plane with texture by 90 degrees

I've been working on developing an fps game, but I'm encountering an issue where the floor disappears from the scene when I try to rotate it close to 90 degrees. Here's the code snippet responsible for creating the plane. var colorMap = new ...

Javascript favorite star toggling

An excellent illustration is the star icon located on the left side of this post. You have the ability to click on it to save this message as a favorite and click again to remove the flag. I have already set up a page /favorites/add/{post_id}/, but I am ...

substituting symbols with colorful divs

I'm looking to add some color to my text using specific symbols. (), ||, and ++ are the symbols I'm using. If a text is enclosed in | symbols, it will appear in blue, and so on... Here is the code in action: const text = "|Working on the| i ...

Adding embedded attributes from a different object

I am facing a challenge with two arrays called metaObjects and justObjects. These arrays consist of objects that share a common property called id. My goal is to merge properties from the objects in these separate arrays into a new array. const metaObje ...

An issue occurred while evaluating the Pre-request Script: Unable to access the 'get' property of an undefined object

I need help accessing the response of my POST request in Postman using a Pre-request Script. Script below : var mobiles = postman.environment.get("mobiles"); if (!mobiles) { mobiles =["8824444866","8058506668"]; } var currentMobile = mobiles. ...

How to Utilize Vue and Checkboxes for Filtering a List?

My current challenge involves filtering a list of posts based on userId using checkboxes. The data is being retrieved from: https://jsonplaceholder.typicode.com/posts. I aim to include checkboxes that, when selected, will filter the list by userId. Here is ...

Building routes for nested relationships in the MEAN stack: A comprehensive guide

Within my Mongoose Schema, I am dealing with two models - User and Plans. Each user can have multiple plans, so in the Plans Schema, I am embedding a userID like this: var PlanSchema = new mongoose.Schema({ title: {type: String}, userId: {type: Stri ...

Utilize the names from a JSON array to showcase the initial character in a ListView

I am trying to build a Listview of projects with assigned members, and I want to display these members using a Futurebuilder and a Listview.builder. I aim to show their names with the first letter displayed as a CircleAvatar like: 'H' - 'S&a ...

Utilizing Vue.js: Disabling button on image carousel when there is no "next" photo accessible

This is my initial experience with Vue. I am attempting to assemble a slideshow using an array of images. I have successfully managed to disable the "previous" button when the user reaches the beginning of the slideshow, but I am encountering difficulties ...

What is the process for automatically storing a JSON object in a database?

I'm working with a massive Json object that I need to store in a nosql database. I have two main questions: First of all, how can I create the database schema based on this Json object? Secondly, is there any method to automatically insert this obje ...

Obtaining a button from a dialog in Google Apps

It seems like I'm overlooking something really simple here, but I'm struggling to enable an interface button from a dialog box in Google Apps. When I try setting the disabled attribute to false in a this object under the "click" function, the bu ...

Retrieving the selected value from a dropdown menu without having to click on a

I'm facing an issue with 2 dropdown menus outside of an HTML table that is generated by PHP code. There's a submit button within this table, and here's how it's set up: <!doctype html> Select Year: ...