ember.jsember-data

ember-data relationships not working


Trying to figure out how to use relationships and it just is not working.

// Data
{
    "apps": {
        "-AFCH5-Kvkc_nfQxnpZ8": {
            "name": "Leap Day",
            "playLink": "https://play.google.com/store/apps/details?id=com.nitrome.leapday",
            "price": "0.00",
            "like": 0,
            "show": "-SFCH5-Kvkc_nfQxnpZ8",
            "provider": "-PFCH5-Kvkc_nfQxnpZ8",
            "imageUrl": "https://www.google.com/url?q=https://lh3.googleusercontent.com/5oR-jbrmKNWqdWQnwrDjPD2PJUJekGK_BUAQOjKD3GuJRTk2MLVzuU2HJ0wyY2BYPsdS%3Dw300-rw&sa=D&ust=1464126095843000&usg=AFQjCNH0RSH6_0bA_EUqnZaldtUxCH1fAw"
        },
        "-AFCH5-Kvkc_nfQxnpZ9": {
            "name": "Gangfort",
            "playLink": "https://www.google.com/url?q=https://play.google.com/store/apps/details?id%3Dcom.gangfort.game.android&sa=D&ust=1464126095844000&usg=AFQjCNFSTZ1p_uBvIHYw97c29XwJU3gEjw",
            "price": "1.99",
            "like": 0,
            "show": "-SFCH5-Kvkc_nfQxnpZ8",
            "provider": "-PFCH5-Kvkc_nfQxnpZ8",
            "imageUrl": "https://www.google.com/url?q=https://lh3.googleusercontent.com/DV5mFhDQ2ADEbiF0S4cxL313JDqRazy9et7Etky5WtH7gxsm9DvbHhb52N0MH1swgfzR%3Dw300-rw&sa=D&ust=1464126095844000&usg=AFQjCNEymzxjrdN8wwL4qN40w5i8i9MlPw"
        }
    },
    "shows": {
        "-SFCH5-Kvkc_nfQxnpZ8": {
            "number": 432,
            "name": "Google I/O Secrets Revealed",
            "date": "05/22/2016",
            "app": ["-AFCH5-Kvkc_nfQxnpZ8", "-AFCH5-Kvkc_nfQxnpZ9"],
            "url": "http://podnutz.com/aaa432/"
        }
    },
    "providers": {
        "-PFCH5-Kvkc_nfQxnpZ8": {
            "firstName": "Steve",
            "lastName": "McLaughlin",
            "nick": "D2d",
            "app": ["-AFCH5-Kvkc_nfQxnpZ8", "-AFCH5-Kvkc_nfQxnpZ9"]
        }
    }
}

Here is the app model import Model from 'ember-data/model'; import attr from 'ember-data/attr'; import { belongsTo } from 'ember-data/relationships';

export default Model.extend({
  name: attr('string'),
  playLink: attr('string'),
  price: attr('string'),
  like: attr('number'),
  show: belongsTo('show', {
    async: true
  }),
  provider: belongsTo('provider', {
    async: true
  }),
  imageUrl: attr('string')
});

Here is the show model

import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';

export default Model.extend({
  number: attr('number'),
  name: attr('string'),
  date: attr('date'),
  apps: hasMany('app'),
  url: attr('string')
});

Here is my route

import Ember from 'ember';

export default Ember.Route.extend({
  model() {
    return this.store.findAll('app');
  }
});

Here is what the ember console looks like

Ember Console

So the problem is when I try to access the show object in my template, its not coming up

{{#each model as |show|}}
    {{app.show.name}}
{{/each}}

Update

From the looks of the markup it seems like something is working here

enter image description here

Here is the console when I log app.show

enter image description here


Solution

  • Looks like apps: hasMany('app') reference in your show model is overwriting your relationship defined in the shows model.