# hasMany association

**URL:** <https://discuss.emberjs.com/t/hasmany-association/11119>\
**Category:** Uncategorized\
**Created:** [July 10, 2016, 11:09am UTC](https://discuss.emberjs.com/t/hasmany-association/11119 "2016-07-10T11:09:05Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ghoshnirmalya](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ghoshnirmalya/32/12423_2.png) [@ghoshnirmalya](https://discuss.emberjs.com/u/ghoshnirmalya)\
**Post date:** [July 10, 2016, 11:09am UTC](https://discuss.emberjs.com/t/hasmany-association/11119/1 "2016-07-10T11:09:05Z")

</div>

I asked the question on StackOverflow ([javascript - hasMany association in Ember js - Stack Overflow](http://stackoverflow.com/questions/38289037/hasmany-association-in-ember-js/38289732#38289732)) but didn’t get much help. So, I’m asking it here:

```
// app/models/card.js

export default Model.extend({
  title: attr('string'),
  description: attr('string'),
  users: hasMany('user')
});

// app/models/user.js

export default Model.extend({
  email: attr('string'),
  name: attr('string'),
  cards: hasMany('card')
});

// app/routes/card/new.js

actions: {
  save(title, description) {
    const newCard = this.get('store').createRecord('card', {
      title,
      description
    });

    this.get('store').findRecord('user', 1).then(function(user) {
      newCard.set('users', user);
      console.log(newCard);
    });

    newCard.save().then((card) => {
      // go to the new item's route after creating it.
      this.transitionTo('card.card', card);
    });
  }
}

```

So, when I’m saving a card, it is throwing me this error:

Assertion Failed: You must pass an array of records to set a hasMany relationship.

I tried doing `newCard.set('users', [user])` but the response is

```
{
   "data":{
      "attributes":{
         "title":"sad",
         "description":"asdasd"
      },
      "relationships":{
         "‌​users":{
            "data":[

            ]
         }
      },
      "type":"cards"
   }
}

```

where the `users.data` is a blank array. My backend expects the `users.data` to be something like `[1, 2, 3]` or even `[1]`.

I want to create an association between the newly created card and the user.

Other info:

Repo link: [https://github.com/ghoshnirmalya/hub-client](https://github.com/ghoshnirmalya/hub-client)

Ember : 2.6.1

Ember Data : 2.6.1
