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

Fix: Optional MorphToSelect does not set key column to null #11275

Conversation

coleshirley
Copy link
Contributor

@coleshirley coleshirley commented Feb 6, 2024

Description

I have an optional MorphToSelect field:

MorphToSelect::make('morphable')
    ->types([
        MorphToSelect\Type::make(MorphType1::class)
            ->titleAttribute('name'),
        MorphToSelect\Type::make(MorphType2::class)
            ->titleAttribute('name'),
        MorphToSelect\Type::make(MorphType3::class)
            ->titleAttribute('name'),
    ]),

When I set the type field back to "Select an option" and save the morphable_id column is still set even though the morphable_type is set to null.

This PR adds an override of the dehydrateState() method that manually sets the "key" column to null if the field is not required

Code style

  • composer cs command has been run.

Testing

  • Changes have been tested.

Documentation

  • Documentation is up-to-date.

@danharrin
Copy link
Member

Thanks! I've given this a refactor and a few tests to make it an official API, instead of overriding just for this component

@danharrin danharrin added the bug Something isn't working label Feb 7, 2024
@danharrin danharrin added this to the v3 milestone Feb 7, 2024
@danharrin danharrin merged commit 83ccfc1 into filamentphp:3.x Feb 7, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants