Replies: 1 comment
-
I agree, that is a great feature to have and in some cases it is almost impossible to avoid it. Imagine that you have a storefront that points to objects of different types that have different properties. With polymorphism you would just have a single Without polymorphism how would you deal with such scenario? Duplicate same properties for each distinct type you have in a system? How would you paginate results then? How to add new field that is shared across different types? Create N different migrations for each product type? How to make a unified API that points to a store front item, instead of building routes for each product type? And lot's of other problems. Polymorphism have it's cons for sure such as having to do N extra queries for each type that is being fetched. But in this case developers just need to understand it and limit the amount of distinct types they use with polymorphic tables. Polymorphism goes against the relational database normalization theory but lots of modern things do as well. Having Personally I don't see why Lucid shouldn't have such functionality while both Laravel and Rails have it. I'm using such pattern on a relatively high-load product with Laravel with a table that have ~3 million rows in it and 3-5 different types of objects it points to. Haven't seen any significant problems or latency issues with it on RDS instances with SSD. @thetutlage @RomainLanz sorry for pinging you, but maybe you could share your opinion about this problem and how would you solve issues I listed above without using polymorphism? Is there a better way that I'm not aware of? I've seen Harminder's responses from 2017-2018 but he didn't mention any specific concerns and may be he changed his opinion since then? |
Beta Was this translation helpful? Give feedback.
-
Since adonis is inspired by Laravel framework I miss a very common use case on all applications I've worked which is polymorphic relationships/tables/models the same way Laravel does. So I'd like to suggest a polymorphic relationships and tables with Adonisjs. Here are some models/tables very commonly used with polymorphic relations:
These are all common and already used use cases that I've worked with using Laravel and it was just amazing. I really would love to use it in Adonisjs. ❤️
By the way, congratulations for this awesome framework 🚀 ❤️
23 votes ·
Beta Was this translation helpful? Give feedback.
All reactions