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
I have a model with a field that stores data in a JSON db column. I am casting that data as "array" on the model.
protected $casts = [ 'types' => 'array', ];
When creating a new approval on the model, the data from that field is escaped before it's written to the approval table. When approving the model with:
Approval::where('id', 1)->approve();
The escaped data is written to the intended model's table but isn't cast as an array by Laravel because of the extra characters on the string.
I think what's needed is at line 32 in MustBeApproved.php.
change: if (isset($model->casts[$key]) && $model->casts[$key] === 'json') {
to if (isset($model->casts[$key]) && ($model->casts[$key] === 'json' || $model->casts[$key] === 'array')) {
I made the above change, created a new model, that saved an approval, and then approved the model. It works. I'm happy to submit a PR for the change if needed.
The text was updated successfully, but these errors were encountered:
Looking over the existing tests, it appears there is already a test for a model with an array cast. The test description is "approve a attribute of the type Array".
It creates a table with a json column ('data')
It creates a model with MustBeApproved and casts 'data' as an array
It creates a new model and fills 'data' with an array
Does the standard database checks
Model is approve with ->approve()
Checks database again after approval
Fetches the model and checks that it is an array
This seems exactly the test that's needed for my code edit, but I can't see why that test has passed before based on what is being written to my model.
- Adds a new test case to validate handling of nested array attributes through the approval process.
- Ensures multiple array-cast attributes are handled correctly.
- Verifies preservation of complex nested data structures.
- Confirms data integrity is maintained and array casting works after model retrieval.
- Addresses Issue #68.
I have a model with a field that stores data in a JSON db column. I am casting that data as "array" on the model.
protected $casts = [ 'types' => 'array', ];
When creating a new approval on the model, the data from that field is escaped before it's written to the approval table. When approving the model with:
Approval::where('id', 1)->approve();
The escaped data is written to the intended model's table but isn't cast as an array by Laravel because of the extra characters on the string.
I think what's needed is at line 32 in MustBeApproved.php.
change:
if (isset($model->casts[$key]) && $model->casts[$key] === 'json') {
to
if (isset($model->casts[$key]) && ($model->casts[$key] === 'json' || $model->casts[$key] === 'array')) {
I made the above change, created a new model, that saved an approval, and then approved the model. It works. I'm happy to submit a PR for the change if needed.
The text was updated successfully, but these errors were encountered: