0

If I had an object

DS.defineResource({
    name : 'parent',
    relations : {
        hasMany : {
            child : {
                localField : 'children',
                foreignKey : 'parentId'
            }
        }
    }
})
DS.bindOne('parent', 1, $scope)

and I make a change to an attribute on a child parent.children[4].name='joey', how can I include that change as part of a save:

$scope.parent.DSSave();

How can I do that?

end-user
  • 2,845
  • 6
  • 30
  • 56

1 Answers1

0

The reason this doesn't work in JSData 2.x is that the relation getters are non-enumerable, and thus aren't picked when the record is serialized and sent to the adapter. You'd have to manually construct the payload to send relations to the adapter:

const payload = {};
Object.keys(parentRecord).forEach((key) => payload[key] = parentRecord[key]);
payload.childRecords = parentRecord.childRecords;
DS.update('parent', parentRecord.id, payload)

In JSData v3 it would be something like this:

store.update('parent', parentRecord.id, { with: ['childRecords'] })
jdobry
  • 1,041
  • 6
  • 17