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

Make Model Castable Porperties inheritable #57

Merged

Conversation

misakstvanu
Copy link
Contributor

@misakstvanu misakstvanu commented Sep 9, 2023

There is something I would consider an issue. It is not possible to have a super-class Model with Lift trait and more classes that inherit it. CastValues's static property $modelCastableProperties would be in that case built only once - with data of the first calling class. Like so:

class Super extends Model {
    use Lift;
}
class A extends Super {
    protected $casts = ['data' => 'integer']
}
class B extends Super {
}

$entityA = A:create(['data' => 123]); // Casts are built, merged and saved.
$entityB = B:create(['data' => 123]); // There is no rebuild for class B, casts created in previous class A are merged. Result is  ['data' => 'integer'].

There is probably a cleaner solution, but I propose saving the casts per static::class.

Copy link
Owner

@WendellAdriel WendellAdriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since I never extend a model I forget that this is possible hahahahaha
Good catch here, thanks!

@WendellAdriel WendellAdriel merged commit 4da3c5c into WendellAdriel:main Sep 18, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants