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

Remove minimum types restriction from Morphable relationship declarations #304

Open
efmjackhardcastle opened this issue Feb 10, 2025 · 1 comment

Comments

@efmjackhardcastle
Copy link

I completely understand why this is here, if you have a Morphable field, its a reasonable assumption that it must be morphable to more than one type, otherwise why be morphable in the first place?

In reality, we're adding relationships we know long-term are going to be morphable, i.e. for a model morph on an approval system, but on it's first iteration we're only supporting one type, making it morphable for future iterations, but we don't have a second type to support yet.

Can't see any issues with removing the > 1 check in the MorphTo class, I've overriden this in our codebase to remove the restriction and works fine. The other option is to pass the same type in twice.

     public static function make(string $fieldName, array $relations): self
    {
        /* @phpstan-ignore-next-line */
        return new self($fieldName, $relations);
    }

    /**
     * MorphMany constructor.
     */
    public function __construct(string $fieldName, array $relations)
    {
        parent::__construct($fieldName);
        $this->relations = $relations;
    }

Both workarounds seem to hold up, but it'd be nice if this was an option in the package itself?

Thanks!

@efmjackhardcastle
Copy link
Author

Happy to raise a PR, just wanna double check I'm not missing something before making the change.

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

No branches or pull requests

1 participant