vierge-noire / cakephp-fixture-factories

CakePHP Fixture Factories
https://vierge-noire.github.io/
MIT License
85 stars 20 forks source link

How to specify database connection other than `test`? #174

Closed ishan-eventrac closed 2 years ago

ishan-eventrac commented 2 years ago

In fixture classes there a way to set database connection name(via $connection) in order to insert data into that database.

How can we achieve same with fixture factories?

pabloelcolombiano commented 2 years ago

@ishan-eventrac generally the test data will be inserted in the test DB as documented here.

You should be able to set the connection of your factory in the initialize method as follows:

    protected function initialize(): void
    {
        $this->getTable()->setConnection(ConnectionManager::get('test_foo'));
    }