Polymorphic models

In a nutshell, the best advice is: design it in the way it is best for the database because Elixir/Ecto will be able to handle the code reuse bits easily. It may even be a module named Request and then you have specific FooRequest, BarRequest, BazRequest for each type. There is no reason to worry about inheritance nor couple your DB design with your code, as single table inheritance in Rails would do, because in Elixir you can just pipe the data to the appropriate modules.

Abstract tables should work just fine with Ecto schema. Even in migrations, you can pass the options key when creating tables: https://hexdocs.pm/ecto/Ecto.Migration.html#table/2

Our belongs_to docs also talk about polymorphism a bit, so it may have relevant feedback: https://hexdocs.pm/ecto/Ecto.Schema.html#belongs_to/3

1 Like