Monday, January 28, 2013

$useDbConfig being ignored in 1.3.10

I have an app that was developed using CakePHP 1.3.10.  I am now trying to add a controller for a model that is in a different database.  The code for the model is very simple:

class Cdrs extends AppModel
{
  /**
   *
   * @var string The name of the model
   */
  var $name = 'Cdrs';

  /**
   *
   * @var string Alternate database connection information for this model
   */
  var $useDbConfig = 'otherdb';

  /**
   *
   * @var string The name of the table for this model
   */
  var $useTable = 'cdrs';
}

In database.php I added in otherdb as follows:
class DATABASE_CONFIG {

    var $default = array(
        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'user1',
        'password' => 'password1',
        'database' => 'db1',
        'prefix' => '',
    );

    var $otherdb = array(
        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'user2',
        'password' => 'password2',
        'database' => 'db2',
        'prefix' => '',
    );

    var $test = array(
        'driver' => 'mysql',
        'persistent' => false,
        'host' => 'localhost',
        'login' => 'user',
        'password' => 'password',
        'database' => 'test_database_name',
        'prefix' => '',
    );
}

However, the controller is giving me the error
Error: Database table cdrs for model Cdr was not found.

When I step through the code in the debugger I see the following stack trace
cake/libs/model/model.php.Model->setDataSource:2831   
cake/libs/model/model.php.Model->__construct:469   
cake/libs/class_registry.php.ClassRegistry->init:150   
cake/libs/controller/controller.php.Controller->loadModel:637   
cake/libs/controller/controller.php.Controller->constructClasses:502   
cake/dispatcher.php.Dispatcher->_invoke:186   
cake/dispatcher.php.Dispatcher->dispatch:171   
app/webroot/index.php.{main}:83   

The $dataSource being passed in to setDataSource is "default" instead of "otherdb"
If I change the value in the debugger to "otherdb" then the error goes away.

Why is the $useDbConfig being ignored?  What am I doing wrong?

Is it possible that this was a bug that was fixed in a later version of 1.3?  I can probably upgrade within 1.3 if necessary but I cannot upgrade to 2.x at this point in the development process.

Any help would be appreciated.

--
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 post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: