-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
Relation::tableNameAsMorphType breaks morphTo relations #35519
Comments
Can you create a quick repo that reproduces the problem? Please commit custom code separately from the base skeleton. |
I've come to the conclusion that it's impossible to solve this one. Since with the inverse here you only have the context of the alias there's no way to derive the class name from it as you simply don't know the namespace of the model. At the moment I'm more leaning to reverting this completely as we can't ever ship this properly. Mapping custom morph types will always need to be done manually through the morph map. |
Checking the problem |
It seems that the
Thanks, @dmason30 for clarification. |
I think it's best to revert this. |
@driesvints Yeah, the first option not possible with one model. it should accept a list of "Imagable models" which is not very good either. |
One consideration for option 3 is that you can still use Say the code was changed to attempt to morph table names into models via If you had a table 'posts' but for the benefit of this example for some reason your model was called class AppServiceProvider extends ServiceProvider
{
public function boot()
{
Relation::tableNameAsMorphType();
Relation::morphMap(['posts' => BlogPost::class]);
}
} The benefit here keeps it using the table name as the default so you don't end up adding all your models to If your models were outside of the default If you decide to revert fair enough. I have lived with having a 100 models listed in my Perhaps the only true solution is what the below package attempts which scans models and caches the https://github.com/sebastiaanluca/laravel-auto-morph-map |
Let's just revert it. |
@driesvints can you send in the revert PR? |
@taylorotwell will do |
Description:
The #35257 PR doesn't seem to work with
morphTo
relations. You end up with anClass 'posts' not found
when using in conjunction withRelation::tableNameAsMorphType();
Steps To Reproduce:
Taking the example from the docs where
imageable
could be aPost
or aUser
.https://laravel.com/docs/8.x/eloquent-relationships#one-to-one-polymorphic-relations:
Add the below to
AppServiceProvider
in theboot
method:The below code will throw the exception described above:
The text was updated successfully, but these errors were encountered: