我有三个表,incidents
,incident_properties
和property_types
。Zend递归表依赖关系数据检索
我想要做的是:
- 查询的
incidents
表一行 - Retreive其所有属性(这是键值行和TYPE_ID)
- 对于每个属性, - 从
property_type
表
所以我成立了这个表关系检索其类型
class Incidents extends Zend_Db_Table_Abstract
{
protected $_name = 'incidents';
protected $_dependentTables = 'Properties';
}
class IncidentProperties extends Zend_Db_Table_Abstract
{
protected $_name = 'incident_properties';
protected $_dependentTables = 'PropertyTypes';
protected $_referenceMap = array(
'Incidents' => array(
'refTableClass' => 'Incidents',
'refColumns' => 'incident_id'
)
);
}
class PropertyTypes extends Zend_Db_Table_Abstract
{
protected $_name = 'incident_property_types';
protected $_referenceMap = array(
'Properties' => array(
'refTableClass' => 'IncidentProperties',
'refColumns' => 'property_type_id'
)
);
}
在我incidents
模型映射器,我想这样做:
$select = $this->_dbTable->select()->where('id = ?',$incident->get_id());
$incident_properties = $this->_dbTable
->fetchRow($select)
->findDependentRows('IncidentsProperties')
->toArray();
print_r($incident_properties);
而且在$incident_properties
检索其类型行内的属性键,值和类型。
任何想法如何实现这个正确的方式?
好吧,我已经明白了, 但我还有一个问题是有点偏离主题 - 未使用这些findDependentRowset()和findParentRow()函数 生成两个更多的选择查询到数据库,这可能比只使用一个JOIN查询? – Xeus