You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
using .update() on a model with attribute changes that have to be cast does not work.
It looks like all values are passed directly to the QueryBuilder without being transformed in any way.
To Reproduce
classUser(Model):
__casts__= {"roles": "json"}
__fillable__= [
"name",
"age""roles",
]
user=User.create({
"name": "Bob",
"age": 26,
"roles": ["admin"],
}, casts=True).fresh()
# now we want to update the modeluser.update({
"roles": ["std_user"],
})
this fails in postgres with an error similar to the following
column "roles" is of type json but expression is of type text[]
LINE 1: ..."roles" = ARRAY['adm...
^
HINT: You will need to rewrite or cast the expression.
Current workaround is to update each attribute on the model separately and use .save() which casts the attributes to their intended column type correctly.
eg
Describe the bug
using .update() on a model with attribute changes that have to be cast does not work.
It looks like all values are passed directly to the QueryBuilder without being transformed in any way.
To Reproduce
this fails in postgres with an error similar to the following
Current workaround is to update each attribute on the model separately and use .save() which casts the attributes to their intended column type correctly.
eg
But this is just less clean if many attributes are required for update.
Expected behavior
I should be able to use .update() on a model with attributes that are in the casts list
Desktop (please complete the following information):
What database are you using?
The text was updated successfully, but these errors were encountered: