Open CharlieIGG opened 5 years ago
I made some specs to reproduce but they passed. Can you post the resource class definition?
This is the real thing:
import resourceLibrary from './library'
class Car extends resourceLibrary.Base {
static define() {
this.attributes('year', 'prices')
this.belongsTo('engine')
this.belongsTo('make')
this.belongsTo('model')
}
}
export default resourceLibrary.createResource(Car);
As a temporary workaround for this I've decided to call
myResourceInstance.update({
jsonField: JSON.stringify({stuff: 1234})
})
And setup a before_save
filter on my Rails app that parses that JSON before attempting to save it.
update
only sends changed fields to the server. If an attribute is not added in attributes
then it won't be sent:
this.attributes('year', 'prices', 'jsonField')
@nicklandgrebe my example didn't match the real-world definition of the resource itself. My bad.
In the real example prices
is the JSONB field. And as you can see it was already declared.
If instead of using update
you use assignAttributes
, what does changedFields
return?
@nicklandgrebe I'll test it out either today or tomorrow and get back to you. 👍
Finally had a chance to test this out.
if I call:
car.assignAttributes({
prices: update,
})
I get:
My backend server is using PostgreSQL as a DB. For a specific field in my model, I have a JSONB column.
When I call:
Then the update reaches my server without this parameter (basically it updates the model instance without any actual changes).
If I instead send some other primitive data type as the value of
jsonField
then I can see it come through in the request's parameters.Any ideas how to make this work, without moving away from the JSON:API standard in my server?