# Missing Model Relationship

**URL:** <https://discuss.emberjs.com/t/missing-model-relationship/11210>\
**Category:** Uncategorized\
**Created:** [July 21, 2016, 4:17pm UTC](https://discuss.emberjs.com/t/missing-model-relationship/11210 "2016-07-21T16:17:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iaskquestions](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@iaskquestions](https://discuss.emberjs.com/u/iaskquestions)\
**Post date:** [July 21, 2016, 4:17pm UTC](https://discuss.emberjs.com/t/missing-model-relationship/11210/1 "2016-07-21T16:17:19Z")

</div>

Hi All 🙂

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!

---

<div class="post-metadata">

**Author:** ![dustinfarris](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/dustinfarris/32/13765_2.png) [@dustinfarris](https://discuss.emberjs.com/u/dustinfarris)\
**Post date:** [July 22, 2016, 4:17am UTC](https://discuss.emberjs.com/t/missing-model-relationship/11210/2 "2016-07-22T04:17:27Z")

</div>

Possible that your `posObj.save()` has not resolved before you push it to poss hasMany—effectively meaning it doesn’t have an id yet and you’re adding an object with a null id to the hasmany.

Try this

```
let pos = this.get('store').createRecord('pos', { name: posname });
let user = this.get('store').createRecord('user', { username: user });
pos.save().then(pos => {
  user.get('poss').pushObject(pos);
  user.save();
});

```

Or something like that.

---

<div class="post-metadata">

**Author:** ![tomchen](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tomchen/32/12234_2.png) [@tomchen](https://discuss.emberjs.com/u/tomchen)\
**Post date:** [July 22, 2016, 6:32am UTC](https://discuss.emberjs.com/t/missing-model-relationship/11210/3 "2016-07-22T06:32:57Z")

</div>

[Ember - 4.6 - Ember API Documentation](http://emberjs.com/api/classes/RSVP.Promise.html) and [GitHub - tildeio/rsvp.js: A lightweight library that provides tools for organizing asynchronous code](https://github.com/tildeio/rsvp.js/) are good places to look for more info on promises in Ember. The second link is the library that Ember uses for handling promises / asynchronous acode. 🙂
