Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

markApproved, markRejected, ... functions incompatible with models with attributes with array casts #35

Open
koapeadu opened this issue Oct 15, 2018 · 2 comments
Labels

Comments

@koapeadu
Copy link

koapeadu commented Oct 15, 2018

I have a model with an array cast on one attribute foo.

protected $casts = [
        'foo' => 'array',
];

But the SQL type is VARCHAR.
When the any of markApproved, markRejected, markPostponed, markPending is called, it causes the attributes array to be changed from

$attributes = [
    ...
    'foo' => '["mango","pineapple","pawpaw"]'
    ...
]

to

$attributes = [
    ...
    'foo' => [
        "mango", "pineapple", "pawpaw"
    ]
    ...
]

which leads to unexpected value exceptions when trying to save the model

@koapeadu
Copy link
Author

Ok I was able to fix it by changing the $new->attributesToArray() to $new->attributes in the Moderatable trait.
So the markApproved function for example changes to

public function markApproved()
{
    $new = (new static)->newQueryWithoutScope(new ModerationScope())->approve($this->id);
    return $this->setRawAttributes($new->attributes); // instead of $this->setRawAttributes($new->attributesToArray())
}

@hootlex Kindly test this and update. Thanks

@koapeadu koapeadu changed the title markApproved, markRejected, ... functions modify attributes with casts defined on them markApproved, markRejected, ... functions incompatible with models with attributes with array casts May 8, 2019
@koapeadu
Copy link
Author

koapeadu commented May 8, 2019

I submitted a PR to fix it. #45

@hootlex hootlex added the bug label Oct 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants