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

MorphTo relations are broken in some cases since v11.33.0 #53624

Open
sebj54 opened this issue Nov 21, 2024 · 2 comments
Open

MorphTo relations are broken in some cases since v11.33.0 #53624

sebj54 opened this issue Nov 21, 2024 · 2 comments

Comments

@sebj54
Copy link
Contributor

sebj54 commented Nov 21, 2024

Laravel Version

11.33.0

PHP Version

8.3.13

Database Driver & Version

No response

Description

Since version 11.33.0 and more precisely this commit: 8528d04, the constraints applied on MorphTo relations have changed.

For the example, let's say I have the example relation from the docs: https://laravel.com/docs/11.x/eloquent-relationships#one-to-one-polymorphic-model-structure. So I have an Image model with an imageable relation (MorphTo), pointing to a Post.

Before that commit, the foreign key constraint was correctly added to the relation query: it added a where like this:

[
        "type" => "Basic"
        "column" => "posts.id"
        "operator" => "="
        "value" => 252
        "boolean" => "and"
]

Now with the latest version, the only where is:

[
        "type" => "Null"
        "column" => ""
        "boolean" => "and"
]

This bug breaks some packages like https://github.com/kirschbaum-development/eloquent-power-joins.

Steps To Reproduce

  • Create a MorphTo relation (for example Image::imageable)
  • Call the relation: $relation = (new Image)->imageable()
  • Dump the relation and watch the wheres of the query
  • Change your Laravel version from 11.32.x to 11.33.x

Feel free to ask if you need a proper reproduction to work on this but I think you have some test projects already covering this feature.

Thanks for your help!

@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@sebj54
Copy link
Contributor Author

sebj54 commented Nov 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants