如何使用"两个数据库"编写连接查询在cakephp

时间:2017-02-23 12:36:52

标签: cakephp

如何使用cakephp中的两个数据库编写连接查询。这是我的代码,我想连接两个数据库连接,但我有一个Db连接。

import numpy as np

myArr=np.array(myList)

#1
myArr = myArr[np.in1d(np.arange(myArr.size), anotherList, invert = True)]

#2
TargetIndex = next(np.nonzero(myArr > someBoundary)[0].flat, myArr.size)

#3
def myFunction():
    return (np.abs(myArr) <= someLimit).astype(int)

#4
np.where(np.abs(myArr) < someLimit, 0, myArr)

1 个答案:

答案 0 :(得分:0)

我认为你不能以这种方式“连接”两个ConnectionManagers。

您可能有两种选择:

选项A - 根据this post中的示例,静态指定数据库名称作为表初始化的一部分:

public function initialize(array $config)
{
    $this->table('databaseName.tableName');
    // ...
}

选项B - 指定替代连接&amp;延迟加载

您可以在表级指定特定模型的alternative connection names

class ClassSchedule extends Table
{
    public static function defaultConnectionName() {
        return 'test';
    }
}

请注意,这不能在使用default连接的其他表的连接中使用。相反,您必须手动“延迟加载”关联数据。作为一般例子(我不知道你的关联是什么,只是一个随机的例子):

$student->class_schedules = TableRegistry::get('ClassSchedules')->find()
    ->where(['student_id'=>$student-id])
    ->toArray();
相关问题