mercredi 25 janvier 2017

Ember data belongsTo relationship saving, but results not visible in a template

I can successfully save a belongsTo relationship, but am not able to see the result in a template.

I cannot seem to populate the belongsTo record - no query is sent to my server to resolve the relationship.

The returned json shows a user_id - but ember is not able to use that to establish the belongs to record.

My question is, how do tell ember to use the user_id in the returned json to establish the belongsTo relationship?

I have 2 models

User

import DS from 'ember-data';

export default DS.Model.extend({
  email:       DS.attr('string'),
  firstName:   DS.attr('string'),
  lastName:    DS.attr('string’)
});

support-request

import DS from 'ember-data';

export default DS.Model.extend({
  user:     DS.belongsTo('user', { async: false }),
  category: DS.attr('number'),
  status:   DS.attr('number'),
  serviceLevel: DS.attr('number'),
  message:  DS.attr('string')
});

This is support-requests/index.js router

import Ember from 'ember';
import DS from 'ember-data';

import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';

export default Ember.Route.extend(AuthenticatedRouteMixin, {

  metaParams: {
    meta: {
      refreshModel: true
    }
  },

  model: function(params) {
    return this.store.query('support-request', params);
  },

});

A successful request is made to: http://localhost:3003/api/rest/support_requests

Which returns 1 record

meta : {total: 1, offset: 0, limit: 0}

support_requests : [
 category : 1
 created : "2017-01-25T08:50:10.588Z"
 id : "588866c24f2a9acd6bfa66e3"
 images : []
 message : "asdfasdf"
 modified : "2017-01-25T08:50:10.599Z"
 service_level : 3
 status : 2
 support_actions : []
 **user_id : "58044e4b7fc427faf6cfe4f9"**
]

Inside my template I have

    
      
      <tr >
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td>
         Edit
        </td>
      </tr>
    

All the supportRequest variables are shown, but the supportRequest.user is empty and does generate a server request to populate the data.




Aucun commentaire:

Enregistrer un commentaire