graphiti-api/spraypaint.js

Dirtiness checks when saving relations

Opened this issue · 0 comments

I have a join table model C that joins models A and B (i.e. on the backend C has two columns a_id and b_id and on the frontend C has two BelongTo's for each of a and b).

If I do the following, saving c does not work.

a = (await A.find(1)).data
b = new B({field: 'value'})
c = new C({a, b})
c.save(with: ["a", "b"])

This fails with the message "A must exist".

The solution is to do c.save(with: ["a.id", "b"]).

IMO this isn't exactly intuitive. I believe it's checking for the dirtiness of a and b to determine if they should be sent up to the server for saving. In this case a isn't dirty and b is dirty (it's new) so only b gets sent up. IMO it should be checking for the dirtiness of c.a and c.b aka the dirtiness of the pointers rather than the things the pointers point to.

Thoughts?