[eluser]BrainFeeder[/eluser]
Hello
We are working on this project where we are using dynamic databases for clients.
I made a basemodel where the db_params gets set in the constructor before parent::__construct() gets called.
All seemed to work just fine untill we had to use include_related(). Datamapper does not know where to look for the model table.
Is this a common problem or is there any solution for this? We are really stuck for the moment.
The code from basemodel:
Code:
function __construct($id = NULL)
{
parent::__construct($id);
}
function getParams($db) {
if ($db != NULL) {
// use these params as default
$db_params = array_merge(array(
'dbdriver' => 'mysql',
'pconnect' => true,
'db_debug' => true,
'cache_on' => false,
'char_set' => 'utf8',
'cachedir' => '',
'dbcollat' => 'utf8_general_ci',
'autoinit' => true,
'stricton' => false,
), $db);
return $db_params;
}
}
In all models that have the dynamic database we extend it from the above basemodel and in the constructor:
Code:
function __construct($id = NULL, $db = NULL)
{
$this->db_params = parent::getParams($db);
parent::__construct($id);
}
Now when I need some data from a dynamic database, I can do:
Code:
$con = new Config(NULL,$this->udb); // $this->udb is set on login and holds the database connection data
$con->get_iterated();
This works great, but when we try to include related tables and/or fields like this:
Code:
$con = new Config(NULL,$this->udb);
$con->include_related('status')->get_iterated();
// OR
// $con->include_related('status')->get();
Datamapper does not know which database to look for.
Maybe we need to set the db_params somewhere else ?