Zend Framework有多个架构/数据库?

时间:2022-09-27 12:51:58

I have a few tables that I've defined like the below examples:

我有几个表,我已经定义了如下例子:

class TableA extends Zend_Db_Table_Abstract
{
    protected $_schema          = 'schema1';
    protected $_name            = 'tablea';
}

class TableB extends Zend_Db_Table_Abstract
{
    protected $_schema          = 'schema2';
    protected $_name            = 'tableb';
}

This seems to work perfectly using one default Db adapter (since the 2 schemas are on the same server).

这似乎可以完美地使用一个默认的Db适配器(因为2个模式在同一台服务器上)。

Code like this works:

像这样的代码有效:

$tableA = new TableA();
$select = $tableA->select();
// $select->__toString() outputs: SELECT * FROM `schema1`.`tablea`

However, when I try to use the same models with any of the Zend Framework table relationship functions (ie: findDependantRowset() or findManyToManyRowset()) the query tries to execute using the schema from the default adapter and does not use the appropriate schema that is defined in the model class.

但是,当我尝试使用与任何Zend Framework表关系函数相同的模型(即:findDependantRowset()或findManyToManyRowset())时,查询尝试使用默认适配器中的模式执行,并且不使用相应的模式在模型类中定义。

Is this a bug? How can I force ZF to use the schema I have defined in the table class and not the one defined as the default in the default Db adapter?

这是一个错误吗?如何强制ZF使用我在表类中定义的模式而不是默认Db适配器中定义的模式?

2 个解决方案

#1


I think this is related to this bug: http://framework.zend.com/issues/browse/ZF-1838

我认为这与这个错误有关:http://framework.zend.com/issues/browse/ZF-1838

It has been fixed in the upstream and should be available in the next release.

它已在上游修复,应在下一版本中提供。

#2


I think you can use a database view table to merge data from 2 schemas, and then use Zend Framework to fetch data from that table.

我认为您可以使用数据库视图表来合并来自2个模式的数据,然后使用Zend Framework从该表中获取数据。

#1


I think this is related to this bug: http://framework.zend.com/issues/browse/ZF-1838

我认为这与这个错误有关:http://framework.zend.com/issues/browse/ZF-1838

It has been fixed in the upstream and should be available in the next release.

它已在上游修复,应在下一版本中提供。

#2


I think you can use a database view table to merge data from 2 schemas, and then use Zend Framework to fetch data from that table.

我认为您可以使用数据库视图表来合并来自2个模式的数据,然后使用Zend Framework从该表中获取数据。