简体   繁体   中英

CakePHP - Associating models across multiple databases

I am using two models, each on a different database, but with the same server log in info (host, user and password)

Model Consumer (Database A) HasMany ConsumerOrder

Model ConsumerOrder (Database B) BelongsTo Consumer

I've done all associations, but at the moment that I run $this->ConsumerOrder->fetch('all'); it is not writing the join, I think it is simply putting a prefix to the name of the database tables, but I don't know how to do it, because it should to change the core.

Any ideas?

SOLVED :

I commented the line 1064 in the file "lib / Model / Datasource / DboSource.php"

The line kept CakePHP to generate the joins as the name of the databases are different.

if ($model->useDbConfig === $linkModel->useDbConfig) { }

Please check have you import Model in controller or not. if not so please import model like that..

$ConsumerOrder= ClassRegistery::init('ConsumerOrder');

After you can write :

$variable = $ConsumerOrder->fetch('all');
print_r($variable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM