How to update a belongTo relation of a model?


#1

Hello, I was wondering how can I update the a belongTo relation of a model? Imagine a User and a Comment model. User hasMany Comment and a Comment belongsTo a User.

The administrator has a screen where he can edit a Comment and change from one User to another. This means that the belongsTo relation of Comment needs to change from User with id 1 to User with id 2.

What I have done so far is I have a select box with the two Users and the option value is the id of the User. When the user is changed the on=changed event on the select box is triggered and I call action on the component backend. From here I get the selected id and I try to set the Comment.user.id = selectedId. However this gives me the error “Error: Assertion Failed: A record’s id cannot be changed once it is in the loaded state”.

Can someone explain to me how this can be done please?


#2

I use ember-selectize to do this like this:

It just updates the post.author with the authors.id but shows the authors.name via content=authors


#3

Thanks that worked great :slight_smile: