-
-
Notifications
You must be signed in to change notification settings - Fork 72
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
Make model table names configurable #165
Conversation
I'll merge it if there will be no other good solutions found next week. |
@vesper8 could you confirm that it is solving your issue? |
Hey @antonkomarev ! Yes I'm happy to say your solution does work! All the modifications to the migrations are not needed however. These are the only two blocks that are needed
Also, noticed I also added Thanks! |
You don't need migration changes because you are already migrated database, but if somebody want to change default table names? It wouldn't work then. But I haven't tried to perform migrations with database prefix. Need to try it too.
Good catch! Fixed. |
Checked database migration with this config: 'storage' => [
'database' => [
'connection' => 'data',
'tables' => [
'love_reacters' => 'sandbox-laravel-love-data.love_reacters',
'love_reactants' => 'sandbox-laravel-love-data.love_reactants',
'love_reaction_types' => 'sandbox-laravel-love-data.love_reaction_types',
'love_reactions' => 'sandbox-laravel-love-data.love_reactions',
'love_reactant_reaction_counters' => 'sandbox-laravel-love-data.love_reactant_reaction_counters',
'love_reactant_reaction_totals' => 'sandbox-laravel-love-data.love_reactant_reaction_totals',
],
],
], Working well. |
excellent : ) thanks for the quick support as usual! |
Excellent solution, would love for this to be merged |
Sorry for the delay. Huge amount of work these days. Will try to find some time to make a release soon. |
I've described another one way to implement table names configuration, but not sure it's a good one because this configuration place is not obvious. |
Can we consider the possibility of extending Models? I think it will be better to be able to define models instead of having table names in a config file. |
Extending of models is not so easy thing because relations will resolve base models which would have different methods and behavior. It will require to have some kind of static registry of all the package models like I've implemented many years ago in Laravel Messenger package or like Laravel Passport is doing it. |
I see 2 cons here:
|
I agree, it might not be the most straightforward answer to solve this specific issue but can be an overall solution for other possibilities as well. |
@antonkomarev your proposed, and already implemented solution, is fine, it is backwards compatible and changes nothing for users who do not wish to change their table names. My only comment is that it could be a little clearer that you must prefix your database name to the table names in the config files for those wishing to use the default table names but on a different connection. In an ideal world simply setting that you wish to use a different connection should be enough but we've seen it doesn't work like that with cross-connection relations As far as extending models as an alternative.. no it isn't so simple at all.. it requires binding multiple classes in a service provider and it's very frail.. 10x more complicated and prone to breaking then your current proposed solution. If your configuration file allowed to specify alternative models like many other packages do then it would be simpler, but still overkill if all one wants to do is change the table name.. or as in my case, simply be able to prefix it with the database name |
Finally, I've found half an hour and released Laravel Love v8.4.0. |
Proof of concept #164 (comment)
Resolves #163
Define any custom table name in
config/love.php
fileTable names with
null
value will use values from Model's$table
class property.Different schema/database could be defined for cross-schema queries by adding its name with dot on the end before the table name, eg.
data.reaction_types
. More details read in #163