EllisLab text mark
Advanced Search
     
Multiple databases and db_params with Datamapper
Posted: 25 August 2012 02:43 PM   [ Ignore ]
Joined: 2012-08-25
4 posts

Hello everyone,

After browsing the forum for some time, I can’t find the answer to my issue.

I’m using Datamapper ORM (1.8.2) and trying to make a specific model connect to another database :

<?php
class Zone extends DataMapper {

 
 
/**
  * override the database connections with this option
  */

 
var $db_params 'dns';
   
    public function 
__construct()
    
{
        
// model constructor
        
parent::__construct();
    
}
}
?> 

According to documentation, this is supposed to make model connect the the dabase described as “dns” in config/database.php.

// Secondary database
$db['dns']['hostname''*****';
$db['dns']['username''*****';
$db['dns']['password''*****';
$db['dns']['database''*****';
$db['dns']['dbdriver''mysql';
$db['dns']['dbprefix''';
$db['dns']['pconnect'FALSE;
$db['dns']['db_debug'TRUE;
$db['dns']['cache_on'FALSE;
$db['dns']['cachedir''';
$db['dns']['char_set''utf8';
$db['dns']['dbcollat''utf8_general_ci';
$db['dns']['swap_pre''';
$db['dns']['autoinit'TRUE;
$db['dns']['stricton'FALSE

Except it doesn’t…

When displaying object details in controller :

$zone = new zone(); 

I get a MySQL error showing the default database and not the database specified in “dns” configuration.

Code debug shows that db_params is not set on my object despite my declaration.

Zone Object ( [db_params] => [error] => [stored] => [prefix] => [join_prefix] => [table] => zones [model] => zone [primary_key] => id [error_prefix] =>

Any idea?

Thanks,

 
Posted: 29 August 2012 04:45 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Joined: 2012-08-25
4 posts

UP!

 
Posted: 29 August 2012 04:49 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

The 1.8.2 release had an issue where model property overrides didn’t always work. This is fixed in 1.8.2.1.

Get the latest datamapper library from http://bitbucket.org/wanwizard/datamapper

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM

 
Posted: 29 August 2012 04:52 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2012-08-25
4 posts

I’ll try this out right away ! Thanks

 
Posted: 29 August 2012 09:31 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-08-25
4 posts

You were right WanWizard. Ugprading Datamapper did the trick.

Many thanks grin

 
Posted: 16 November 2012 02:38 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2012-05-15
2 posts

I hate to bump an old topic like this, but I am having the same exact problem. I’ve downloaded the latest DM from Bitbucket and still cannot get my DM to connect to multiple databases.

Here is my ‘database.php’ file:

http://pastie.org/5388841

And my model:

class Module extends DataMapper {
    
public $db_params 'ohm';
    public 
$has_one = array();
    public 
$has_many = array();

When I try and run it I get the following error:

Error Number: 1146
Table ‘db1.modules’ doesn’t exist

Please help, I’ve tried everything I can think of.

 
Posted: 16 November 2012 07:06 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-11-04
4404 posts

Can you add a constructor you your model, have it call the parent constructor, and after that, do a var_dump($this->db_params)?

 Signature 

Me: WanWizard.eu | My company: Exite | Datamapper: DataMapper ORM