Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4826

Missing Model Relationship

$
0
0

@iaskquestions wrote:

Hi All :slight_smile:

I am using Ember 2.x with Ember Data 2.x with the RESTApdapter.

I am struggling to make sure that my POST requests are sending the right JSON data. For example, I do something like:

 43         let posObj = this.get('store').createRecord('pos', {
 44           name: posname
 45         });
 46         posObj.save();
 48         let uObj = this.get('store').createRecord('user', {
 49           username: user,
 50         });
 52         uObj.get('poss').pushObject(posObj);
 53         uObj.save();

I am expecting this to save the pos object and then create a new user object with a hasMany reference to the pos object.

This does not throw an exception. However, when a request is finally made to my server at the /api/users endpoint, it only shows:

{u'user': {u'username': u'fsdaf', u'pos': [None]}}

Notice that pos shows up as None in the end result. Models look like:

User:

export default Model.extend({
  username: attr(),
  pos: hasMany('pos')
});

Pos:

export default Model.extend({
  name: attr(),
  mos: hasMany('mos'),
  users: hasMany('user')
});

Any help or suggestions would be appreciated!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 4826

Trending Articles