简体   繁体   English

CakePHP-HABTM和模型的不同数据库

[英]CakePHP - HABTM and different databases for models

Lets say I have two different databases with the following tables: 可以说我有两个带有下表的不同数据库:

Auth database: 验证数据库:

users

App database: 应用数据库:

fanpages
fanpages_users

Obviously my User model uses the Auth database, but how do I force HABTM relation to use the App database instead of the Auth database? 显然,我的用户模型使用Auth数据库,但是如何强制HABTM关系使用App数据库而不是Auth数据库?

The error I am getting states: 我得到的错误指出:

Table fanpages_users for model FanpagesUser was not found in datasource Auth.

You need to create another model called FanspagesUser and define $hasMany relation on User model and on Fanpage model. 您需要创建另一个名为FanspagesUser模型,并在User模型和Fanpage模型上定义$hasMany关系。

FanpagesUser.php FanpagesUser.php

    <?php
    class FanpagesUser extends AppModel{
        public  $useDbConfig = 'your database configuration on databases.php';
        public $belongsTo = array('User','Fanpage');

    }

Fanpage.php Fanpage.php

    <?php
    class Fanpage extends AppModel{
        public  $useDbConfig = 'your database configuration on databases.php';
        public $hasMany= array('FanpagesUser');

    }

User.php user.php的

    <?php
    class User extends AppModel{
        public  $useDbConfig = 'your database configuration on databases.php';
        public $hasMany= array('FanpagesUser');

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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