state reset on Model::loadCount() in v1 branch #179
aleksandrpnshkn
started this conversation in
Bugs
Replies: 1 comment
-
We're not supporting v1 anymore, especially since it did some very wonky things as a replacement for custom casts in Laravel 8. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Add column and create relations table in
database/migrations/2014_10_12_000000_create_users_table.php
:Create states:
Register state in
\App\Models\User
:Make Relation model:
Add relation to User:
Uncomment sqlite in
phpunit.xml
:Create and run feature test:
Fail.
In the
\Spatie\ModelStates\HasStates::bootHasStates()
method there is callback$unserializeState
. OnModel::loadCount(...)
theretrieved
event will be fired only with attributesid
andrelations
in the model. There is no attributestate
, but the callback tries to resolve state class for it.$model->getAttribute('state')
returns null, so::resolveStateClass(...)
returns the default state.I added this code to the first line of the
$unserializeState
callback:Now the test passes. The tests from the library are also successful.
Can this fix break anything else? Can it be commited to the repository?
Beta Was this translation helpful? Give feedback.
All reactions