Question

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?

The error I am getting states:

Table fanpages_users for model FanpagesUser was not found in datasource Auth.
Était-ce utile?

La solution

You need to create another model called FanspagesUser and define $hasMany relation on User model and on Fanpage model.

FanpagesUser.php

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

    }

Fanpage.php

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

    }

User.php

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

    }
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top