Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct declination for tables ending on "y" / "ies" #2834

Closed
schaetz opened this issue Jan 12, 2024 · 3 comments
Closed

Correct declination for tables ending on "y" / "ies" #2834

schaetz opened this issue Jan 12, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@schaetz
Copy link

schaetz commented Jan 12, 2024

Drift automatically infers the name of the corresponding entity companion objects by dropping the plural "s" suffix of the table name. However, this does not work correctly when the table name ends on "ies". In my case, I would like the companion object for my "categories" table to be called "CategoryCompanion", but it is called "CategorieCompanion".

Would it make sense to implement this simple pattern matching? I understand that there are reasons not to do it, as you might have tables containing proper names that end on "ie" and cannot be declined, or as someone might use table names in a foreign language where this rule does not apply. Maybe there could be an option to turn it on or off.

If I want to correct this mistake manually, from my understanding I need to use the @DataClassName annotation when using Table classes. Is there a way to do the same thing when using SQL files to generate my tables?

@schaetz schaetz added the enhancement New feature or request label Jan 12, 2024
@simolus3
Copy link
Owner

Do you have the use_data_class_name_for_companions builder option enabled? I think the default name for the companion class would be CategoriesCompanion otherwise. Not exactly what you were looking for, but also not as bad as the current situation.

Is there a way to do the same thing when using SQL files to generate my tables?

Sure, you can use AS RowClassName at the end of your table definition, so something like CREATE TABLE categories (...) AS Category should work.

@schaetz
Copy link
Author

schaetz commented Jan 13, 2024

I eventually migrated my table declaration from the SQL file to Drift Table classes, so that solved my problem. But thanks nonetheless!

@simolus3
Copy link
Owner

I'll close this then, being able to specify the table names in more detail is tracked in #2817.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants