I have a model that I would like to partition across multiple database tables. All the data and functionality will be the same so I would like to use the same module/ecto.model but just have the table it is saved into differ. Further, I won't know until runtime what the table name will be.
Can anyone suggest a way to dynamically set the SCHEMA table name?
Most of the functions that expect a schema, also accept a tuple in the form of {"source", Schema}
, where source is the table name. The source is also properly maintained by structs, so if you select from a particular source, when you update/delete it will resolve to the proper table. There's also Ecto.put_meta(struct, source: "source")
for annotating already build structs.
Those features were also recently expanded to cover more use cases, you can see more in this issue: #1797.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With