laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.62k stars 11.03k forks source link

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

Open sebj54 opened 12 hours ago

sebj54 commented 12 hours ago

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: https://github.com/laravel/framework/commit/8528d04598f99f7cfa0f0aab56c170f8fd583024, 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

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 commented 9 hours ago

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!