tortoise / tortoise-orm

Familiar asyncio ORM for python, built with relations in mind
https://tortoise.github.io
Apache License 2.0
4.66k stars 389 forks source link

Allow function to be passed to `table` #1026

Open Kyzegs opened 2 years ago

Kyzegs commented 2 years ago

Is your feature request related to a problem? Please describe. I'm connecting my Python application to Laravel, a web framework. Laravel generates its database tables with underscores, but Tortoise doesn't. I've looked through the documentation and was unable to find a solution. You could always specify the table in each model, but it'll get pretty annoying when you have hundreds of them.

Describe the solution you'd like It would be awesome if we could pass a function to table in the Meta class. peewee has this functionality. Adopting something like this should make the ORM more compatible with outside sources.

Describe alternatives you've considered I've tried the mentioned solution. Currently, I'm just explicitly setting the table in each of my models.

shanebdavis commented 7 months ago

I agree. I specifically want snake_case_table_names, but in general, it would be nice to establish a base-class with a function for generating table-names from class names.