Two addenda:
1. Does it make a difference that i'm loading a different Model that uses
the 'default' connection *before* Captchas? i've been omitting it because i
didn't think it was relevant. But maybe there's some failure to get the
right defaultConnectionName() because both Models are loaded? It doesn't
seem so at first glance, since i'm specifying $this->Captchas, but who
knows...
2. My apologies for the jab above. i'm actually far less frustrated by
occasional breakage from an alpha framework than i am by trying to unravel
bugs & lack of activity in the "production" release of a popular front-end
framework i use. Lots of other unrelated crap too. To say the least, it's
been a long month.
On Tuesday, 22 July 2014 21:26:20 UTC-4, Joe Theuerkauf wrote:
>
> José:
>
> Sorry for the delayed response. i've been getting burned out (and burned
> up with the weather), so i took a day to breathe.
>
> i called $this->Captchas->defaultConnectionName() from inside the
> ContactsController:
>
> public function index() {
> $this->loadModel('Captchas');
> // PS: i'm using the LogTrait in the class...
> $this->log('defaultConnectionName: ' .
> $this->Captchas->defaultConnectionName());
>
> // ...
> }
>
>
> Output in error.log:
>
> 2014-07-23 01:16:55 Error: defaultConnectionName: default
>
>
> Obviously, not what i was expecting. And that's the value whether i have
> CaptchasTable in the main Model/Table or in Model/Table/Website.
>
> If you have further suggestions, please let me know. i know 3.0 is alpha
> so i do expect some breakage. But when the documentation is so brief &
> doesn't seem to work, it can be frustrating.
> -joe
>
>
> On Monday, 21 July 2014 04:08:18 UTC-4, José Lorenzo wrote:
>>
>> what is returned if you call $this->Captchas->defaultConnectionName() ?
>>
>> On Sunday, July 20, 2014 6:29:33 PM UTC+2, Joe Theuerkauf wrote:
>>>
>>> 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.