My current versions are ember-cli 1.13.8 and ember-data 1.13.11, using ActiveModelAdapter.
I am working with two objects: posts and users. On an individual post page, I have implemented an action that allows users to watch/follow the post.
//post model js
watchedUsers: DS.hasMany('user', { inverse: 'watchedPosts', async: true });
//user model js
watchedPosts: DS.hasMany('post', {inverse: 'watchedUsers', async: true });
//action after clicking button
action: {
addToWatchlist(post) {
//session.current user is declared in an initializer that lets us access the current user easily
post.get('watchedUsers').pushObject(this.get('session.currentUser'));
post.save().then(function() {
console.log('post save success');
}, function() {
console.log('post save fail');
}
}
}
After clicking the follow button in the ember inspector, I can see that the watchedUsers attribute for the post model updates, as well as the watchedPosts for the user model. However, these values disappear upon refreshing the page. It seems like the pushObject function is functioning correctly.
Upon inspecting the PUT
request to my backend to save the post model, I noticed that it does not contain the json entry for the watched_user_ids
. This indicates that it is not being saved properly, which I believe is the root of my issue.
Despite having seeded data in my rails backend that is accessible on the ember side, the many-to-many relationship does not seem to be supported by ember-data. I wonder if there are any specific steps or configurations needed to send/save the json for such a relationship?