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

Table names without schema #42

Closed
angujo opened this issue Oct 31, 2017 · 4 comments
Closed

Table names without schema #42

angujo opened this issue Oct 31, 2017 · 4 comments

Comments

@angujo
Copy link
Contributor

angujo commented Oct 31, 2017

Am working on a dynamic database system that changes DB depending on user organization,

How do I remove the schema from the model table name;

From;
protected $table = 'schema.table_name';

to;

protected $table = 'table_name';

Will appreciate, quite stuck with this after hours of debugging.

Regards.

@angujo
Copy link
Contributor Author

angujo commented Oct 31, 2017

Just realized the issue arises since I extend the models, it picks the new class' name as table name.
I believe another config option should be added for tables to be added, otherwise

'qualified_tables' => false,

should allow third value e.g. NULL
therefore if qualified_tables is NULL, then tables are not added to models;
if FALSE then they are added without schema,
if TRUE they are added with schema.

Once again greatful for the good job you guys are doing with this library.

@CristianLlanos
Copy link
Member

This is interesting. Right now, what you can do is add the property protected $table = null; inside your newly created model, so it'll override the parent's vale. By default Laravel uses the plural form of your class name as the table name, I think.

@angujo
Copy link
Contributor Author

angujo commented Nov 2, 2017

Thanks for the reply.
Looking at .../vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on getTable() (line 1097), this might not work as suggested. It will still pick the property from child class, and getting it as NULL, assume the plural of the child class' name.
Tested it out. and still persists.

Having lots of models extended, was avoiding going through each class adding the $table property and wanted to rely on actual table models for such.

@CristianLlanos
Copy link
Member

I've merged your PR. I'm closing this issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants