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

[Bug]: DatabaseDriver becomes wrong driver #83

Open
simonankele opened this issue Aug 31, 2024 · 4 comments
Open

[Bug]: DatabaseDriver becomes wrong driver #83

simonankele opened this issue Aug 31, 2024 · 4 comments
Assignees
Labels
bug Something isn't working enhancement New feature or request

Comments

@simonankele
Copy link

simonankele commented Aug 31, 2024

What happened?

I have three databases, which I have specified separately as connections in database.php.
php artisan model:show specifies the database, which is the connection. This means that the database is unfortunately defined as a connection in the SchemaModel class $data['database'].

I have corrected this for myself as follows (SchemaModel):

$connection = config('database.connections.' . $data['database']);

        $self = new self(
            $schemaClass,
            $data['class'],
            $connection['driver'],
            $data['table'],
            $data['policy'] ?? null,
            [],
            [],
            $data['observers'] ?? [],
        );

How to reproduce the bug

  1. Creating second database
  2. Add additional connection 'second_connection' in the database.php for the new database
  3. Set $connection to 'second_connection' in the Model
/**
     * The database connection that should be used by the model.
     *
     * @var string
     */
    protected $connection = 'second_connection';
  1. Run php artisan typescriptable
  2. Error because $databaseDriver 'second_connection' is not an Enum in the DatabaseDriverEnum

Package Version

3.1

PHP Version

8.3

Which operating systems does with happen with?

Linux

Notes

Sorry for bad bug report - it's my first ;-)

@simonankele simonankele added the bug Something isn't working label Aug 31, 2024
@ewilan-riviere
Copy link
Contributor

I hadn't considered this possibility, I'll see how to manage this aspect, thanks for the feedback!

@ewilan-riviere ewilan-riviere self-assigned this Aug 31, 2024
@ewilan-riviere ewilan-riviere added the enhancement New feature or request label Aug 31, 2024
@simonankele
Copy link
Author

simonankele commented Aug 31, 2024

Hello,

i have also empty types, when i have dynamic table names like:

    public function scopeSeason(Builder $builder, int $season): Builder
    {
        $this->setTable('Prefix'.$season);

        return $builder->setModel(model: $this);
    }

Perhaps, someone has a better solution to define dynamic tables.

@ewilan-riviere
Copy link
Contributor

ewilan-riviere commented Sep 3, 2024

This is a very different problem from the first, so I'll see how to handle this one later. But yes, I had never thought of using a scope in this way.

I use show:model artisan command, so if Laravel can't see your dynamic table, this module can't see your dynamic table.

@simonankele
Copy link
Author

This is a very different problem from the first, so I'll see how to handle this one later. But yes, I had never thought of using a scope in this way.

I use show:model artisan command, so if Laravel can't see your dynamic table, this module can't see your dynamic table.

Don't know how this should work, because the dynamic table name only takes effect when the scope method is called.

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

No branches or pull requests

2 participants