statamic-rad-pack / runway

Eloquently manage your database models in Statamic.
https://statamic.com/runway
MIT License
107 stars 42 forks source link

[7.x] HasManyField support for MorphMany #533

Closed TheBnl closed 1 day ago

TheBnl commented 1 week ago

Add support for MorphMany.

duncanmcclean commented 4 days ago

Can you please provide some more context around this PR?

What was broken, what errors were you getting, how do the changes in this PR address that?

TheBnl commented 4 days ago

Hi Duncan, Thanks for looking into this, nothing was broken, no errors, nothing to "fix".

The issue this PR addresses was that currently MorpMany is not supported by the module. This PR adds support by checking if the relation uses morph and sets the required "type" next to the currently stored "id".

If you need further information please let me know!

duncanmcclean commented 4 days ago

Hi Duncan, Thanks for looking into this, nothing was broken, no errors, nothing to "fix".

The issue this PR addresses was that currently MorpMany is not supported by the module. This PR adds support by checking if the relation uses morph and sets the required "type" next to the currently stored "id".

If you need further information please let me know!

Oh, I see, thanks! 👍

duncanmcclean commented 1 day ago

Currently, Runway doesn't really support Morph relationships.

When I last investigated adding support for them, I figured it would take quite a bit of refactoring across various parts of the code for them to be supported properly.

For example: we'd need to allow users to select models from multiple models, instead of just the model defined in the field's config.

That doesn't seem like such a big deal at first but we'd have to figure out which columns to display in the selector stack since not all models have the same sets of columns.

We'd also need to make sure that anywhere we resolve relationships, we take the type column into account when figuring out which model needs newing up.

So, while I'm thankful for this pull request, I'd prefer if we added proper support for Morph relationships everywhere, rather than just "patching" it in the places people come accross.

I hope my explanation makes sense! Feel free to upvote the feature request, https://github.com/statamic-rad-pack/runway/discussions/245.

Until we add proper support for morphs, you could potentially look at applying this fix to your project using a composer patch.