i tried this topic before, but the only response was for an older version of Cake...
i'm following this documentation: http://book.cakephp.org/3.0/en/orm/table-objects.html#configuring-connections i'm trying to keep a few tables that would be application-agnostic in a different database. i'm not trying to create associations as mentioned in #3463. i just need to query independent records from these tables. Here's what i have so far: // Config/app.php $config = [ // ... 'Datasources' => [ 'default' => [ // Connection to this DB works. 'database' => 'kodiak', ], 'websites' => [ // Connection is identical, except different 'database' value 'database' => 'websites', ] ] // ... ]; // Model/Table/Websites/CapchasTable.php class CaptchasTable extends Table { public static function defaultConnectionName () { return 'websites'; } } // Controller/ContactsController.php public function index () { $this->loadModel('Captchas'); $captcha = $this->Captchas->find('all', [ 'conditions' => [], 'order' => 'RAND()', 'limit' => 1 ]); // etc. } Here's the error output: SQLSTATE[42S02]: Base table or view not found: 1146 Table *'kodiak.captchas'* doesn't exist Error: An Internal Error Has Occurred. Stack Trace ROOT\vendor\cakephp\cakephp\src\Database\Schema\Collection.php line 113 → Cake\Database\Schema\Collection->_executeSql(string, array) ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 323 → Cake\Database\Schema\Collection->describe(string) ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 127 → Cake\ORM\Table->schema() ROOT\vendor\cakephp\cakephp\src\ORM\Query.php line 110 → Cake\ORM\Query->addDefaultTypes(Cake\ORM\Table) ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 927 → Cake\ORM\Query->__construct(Cake\Database\Connection, Cake\ORM\Table) ROOT\vendor\cakephp\cakephp\src\ORM\Table.php line 724 → Cake\ORM\Table->query() APP/Controller\ContactsController.php line 36 → Cake\ORM\Table->find(string, array) [internal function] → App\Controller\ContactsController->index() ROOT\vendor\cakephp\cakephp\src\Controller\Controller.php line 373 → ReflectionMethod->invokeArgs(App\Controller\ContactsController, array) ROOT\vendor\cakephp\cakephp\src\Routing\Dispatcher.php line 115 → Cake\Controller\Controller->invokeAction() ROOT\vendor\cakephp\cakephp\src\Routing\Dispatcher.php line 87 → Cake\Routing\Dispatcher->_invoke(App\Controller\ContactsController) ROOT\webroot\index.php line 37 → Cake\Routing\Dispatcher->dispatch(Cake\Network\Request, Cake\Network\Response) It doesn't seem to matter if CaptchasTable is in Model/Table or Model/Table/Websites; loadModel('Captchas') doesn't throw errors either way. But the find() call is throwing the error - *regardless where * CaptchasTable* is placed*. When it's commented, the page loads fine (since i'm hitting this error, i haven't actually tried to USE any of the Captcha data in my form yet). So the question is: why isn't defaultConnectionName setting up the connection to the `websites` DB? What's missing? Is it missing documentation & i need to do something more, or is this a bug? i'd appreciate any help before i post this to the Github issues. Thanks. -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
