1

I have a User object which has many route objects.

I load them like:

return User.find(username).then(function(user) {
    return User.loadRelations(user.username, ['routes'])
        .then(function(user) {
            return user;
        });
});

My user object looks like: this

I want to be able to go user.routes.push(newRoute) and then save the user. But I'm unable to push a new route.

Community
  • 1
  • 1
Naila N
  • 45
  • 4
  • Welcome to StackOverflow! If you could post your code it would be helpful -- links to code are a little more difficult to deal with. (You can indent 4 spaces to create a code block.) – jkdev Dec 28 '15 at 02:18
  • Changed it to a code block! Thanks for the reminder :) – Naila N Dec 29 '15 at 01:06

1 Answers1

1

1) js-data <= 2.x does not support deep saving of relations. You would need to add a method to your Resource that sends the nested payload to the adapter.

2) Also, by default, fields specified by the localField option in relation configurations will be a property accessor that dynamically pulls the related items from the store. It doesn't make any sense to push onto the array returned by the property accessor, because it's a different array every time you access the property.

You can remove the property accessor with the linkRelations: false setting, but then you have to manage the links manually. In that scenario you can push onto the array, but that doesn't help with 1) above.

jdobry
  • 1,041
  • 6
  • 17