[8.x] Option to use table names when morphing#38451
Conversation
| } | ||
|
|
||
| return static::class; | ||
| return Relation::$useTableNamesForMorphMap |
There was a problem hiding this comment.
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
registermethod of yourAppServiceProvider:Relation::morphUsingTableNames();Not much else to say about this one 😅