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

Allow table inspection in several database connections at once #1285

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions config/ide-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,26 @@
// 'ide-helper:models --nowrite',
],

/*
|--------------------------------------------------------------------------
| Allow discovery in multiple active databases
|--------------------------------------------------------------------------
|
| When running IDE helper in a multi-tenant context, you would need to
| indicate the database to match the different connections used by your
| models.
|
| This is required if your application has models dispatched both in a common
| database (called landlord or system depending on the libraries) and in a
| tenant specific database (one which will contain data which can vary between
| tenants)
|
| In other cases (single database or no common database), you can leave
| this commented.
*/
// 'db_mapping'=> [
// // laravel connection name => real database name
// 'landlord' => 'homestead',
// 'tenant' => 'test_tenant',
// ],
];
5 changes: 3 additions & 2 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ public function getPropertiesFromTable($model)
}
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
}

$database = null;

$connectionName = $model->getConnection()->getName();
$database = config("ide-helper.db_mapping.$connectionName");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not checked the code yet, but it's wrong to use the global helper here; see all the other instances in this file how they access the config (resolve via container):

$this->laravel['config']->get();

This is important as not everyone runs this library on a full framework installation, some might only use the illuminate/ components and not have this defined.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, sorry about that. This is now fixed.

if (strpos($table, '.')) {
[$database, $table] = explode('.', $table);
}
Expand Down