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
[8.x] Option to use table names when morphing #38451
Conversation
@@ -731,7 +731,9 @@ public function getMorphClass() | |||
return array_search(static::class, $morphMap, true); | |||
} | |||
|
|||
return static::class; | |||
return Relation::$useTableNamesForMorphMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this code is being changed, maybe it would also be useful to add an optional property/method to models (eg. morphableName
) that can be used - so each model can represent its own morphable name itself instead of being done elsewhere in a map?
This change was tried last year and it doesn't work with MorphTo relations and was decided it was impossible to work without a Morph map. |
One doubt: how retrieving from the database would work? From the code changes it is not clear to me. If we still need to use a morph map for retrieving related polymorphic models, wouldn't this be unneeded as the check occurs after checking if a morph map is being used? Sorry if I am missing something obvious on this. |
Well, reverting. |
This reverts commit 5d5655b.
* support class basenames on morphs * table name option for morphmap * rename method * fix test
…avel#38463) This reverts commit 5d5655b.
* support class basenames on morphs * table name option for morphmap * rename method * fix test
…avel#38463) This reverts commit 5d5655b.
@taylorotwell To work around this issue, an alternative is to scan the models and auto-register the morph map when booting the framework. Probably too much of a change for a papercut issue. See https://github.com/sebastiaanluca/laravel-auto-morph-map for a working example. Only drawback is the scanning of models part. Could probably be optimized. What's supported:
Interested in feedback, maybe worth a PR? |
* support class basenames on morphs * table name option for morphmap * rename method * fix test
…avel#38463) This reverts commit 5d5655b.
This PR introduces a new method to instruct Laravel to use table names instead of class names when storing records in polymorphic tables. Typically this method can be called in the
register
method of yourAppServiceProvider
:Not much else to say about this one 😅