Wednesday, March 25, 2015

Re: automatic join for belongsTo association with cross databases not work



Em segunda-feira, 3 de novembro de 2014 06:51:20 UTC-2, Jitendra Rathod escreveu:

In cakephp 2.2.x, we can have automatic join work for cross databases with a simple patch:

"lib/Model/Datasource/DboSource.php function read()
if ($model->useDbConfig === $linkModel->useDbConfig) {
...

to 
if ($model->useDbConfig === $linkModel->useDbConfig || $type=='belongsTo') {
...

But in recent 2.5.x, the read function seems have some changes, 
I was wondering how to make the cross database auto join for belongsTo ?


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

People a have similar problem. In my database bustracker_db i have generic stuff, like(Model cars, Type of contacts)

public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'xxxx',
        'login' => 'xxxx',
        'password' => 'xxxx',
        'database' => 'bustracker_sca_db',
        'prefix' => '',
        'encoding' => 'utf8'
    );
       
 public $bustracker = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'xxxx',
        'login' => 'xxxx',
        'password' => 'xxxx',
        'database' => 'bustracker_db',
        'prefix' => '',
        'encoding' => 'utf8'
    );

In my FuncionarioController a put: public $uses = array('Funcionario', 'FuncionariosContato', 'ContatosTipo');

Funcionario and FuncionariosContato are in the same database(bustracker_sca_db') and ContatosTipo in bustracker_db.

In Funcionario i put:

 public $hasMany = array(
        'FuncionariosContato' => array(
            'className' => 'FuncionariosContato',
            'foreignKey' => 'funcionarios_id',
            'dependent' => true
        )
    );
 
FuncionariosContato i put:

 public $hasOne = array(
            'ContatosTipos' => array(
            'className' => 'ContatosTipos',
            'foreignKey' => 'contatos_tipos_id',
            'conditions' => '',
            'fields' => '',
            'order' => ''
        )
);

A get this error: Table contatos_tipos for model ContatosTipos was not found in datasource default.

CakePhp try to find contatos_tipos in the datasource default, but i change $useDbConfig for $useDbConfig = 'bustracker'.

I try many different ways to solve this.

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

No comments: