# How to create and save a model with a belongsTo relationship in Ember-Data

**URL:** https://discuss.emberjs.com/t/how-to-create-and-save-a-model-with-a-belongsto-relationship-in-ember-data/3238
**Category:** Ember Data
**Created:** [November 4, 2013, 12:32pm UTC](https://discuss.emberjs.com/t/how-to-create-and-save-a-model-with-a-belongsto-relationship-in-ember-data/3238 "2013-11-04T12:32:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![alopez](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/alopez/32/189_2.png) [@alopez](https://discuss.emberjs.com/u/alopez)
#### Post date: [November 4, 2013, 12:32pm UTC](https://discuss.emberjs.com/t/how-to-create-and-save-a-model-with-a-belongsto-relationship-in-ember-data/3238/1 "2013-11-04T12:32:49Z")

</div>

I’m getting the next error when I’m trying to save a new record with an associated relationship. The problem I think is related to the creation of the record because ember doesn’t create any record.

`Uncaught TypeError: Cannot call method 'save' of undefined `

On the one hand, my models are the following (with a one-to-many relationship).

```
App.Kid = DS.Model.extend({
    attribute1: DS.attr("string"),
    parent: DS.belongsTo(parent)
});

App.Parent = DS.Model.extend({
    attribute1: DS.attr("string"),
    kids: DS.hasMany(kid)
});

```

On the other hand, my route is the following.

```
App.KidRoute = Ember.Route.extend({
    model: function (id) {
        var store = this.get('store');
        store.find('usuario', id).then(function(parentmodel){
            return this.store.createRecord('kid', {parent: parentmodel});
        });
    },
    actions:{
        save: function(){
            this.get('currentModel').save();
        }
    }
});

```

Any help would be appreciate. Thanks!

**Editing…**

It is necessary to set the mapping on the adapter through `embedded: 'always'`? Any thoughts?

---

<div class="post-metadata">

### Author: ![fanta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/fanta/32/14645_2.png) [@fanta](https://discuss.emberjs.com/u/fanta)
#### Post date: [November 5, 2013, 5:54pm UTC](https://discuss.emberjs.com/t/how-to-create-and-save-a-model-with-a-belongsto-relationship-in-ember-data/3238/2 "2013-11-05T17:54:43Z")

</div>

hey there, just a suggestion, people here usually does not reply to this type of questions, it would be better to ask in [Newest 'ember.js' Questions - Stack Overflow](http://stackoverflow.com/questions/tagged/ember.js) . This forum is mostly used for ideas, suggestions, and to discuss new features.

---

<div class="post-metadata">

### Author: ![alopez](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/alopez/32/189_2.png) [@alopez](https://discuss.emberjs.com/u/alopez)
#### Post date: [November 5, 2013, 6:28pm UTC](https://discuss.emberjs.com/t/how-to-create-and-save-a-model-with-a-belongsto-relationship-in-ember-data/3238/3 "2013-11-05T18:28:02Z")

</div>

I’d already posted there but I thought this forum would be more helpful for ember questions. Thanks for the clarification!

---

<div class="post-metadata">

### Author: ![nmalancea](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/nmalancea/32/10771_2.png) [@nmalancea](https://discuss.emberjs.com/u/nmalancea)
#### Post date: [April 27, 2015, 6:00pm UTC](https://discuss.emberjs.com/t/how-to-create-and-save-a-model-with-a-belongsto-relationship-in-ember-data/3238/4 "2015-04-27T18:00:43Z")

</div>

@alopez, can you please share the Stack Overflow link for this question? I was wondering about this same thing. Did you figure out how to do it? How to save the id for a related record.
