Zend framework 图中的Zend_Db关系
我有以下表格:Zend framework 图中的Zend_Db关系,zend-framework,zend-db,table-relationships,Zend Framework,Zend Db,Table Relationships,我有以下表格: 每个都有自己的映射器: 产品\型号\数据库\产品 产品\型号\数据库\类别 Product\u Model\u DbTable\u productegrelation 我已经看过了,但我还是不明白 这就是我目前拥有的: class Product_Model_DbTable_Product extends Zend_Db_Table_Abstract { protected $_name = 'product'; protected $_dependentT
每个都有自己的映射器:
产品\型号\数据库\产品
产品\型号\数据库\类别
Product\u Model\u DbTable\u productegrelation
我已经看过了,但我还是不明白
这就是我目前拥有的:
class Product_Model_DbTable_Product extends Zend_Db_Table_Abstract
{
protected $_name = 'product';
protected $_dependentTables = array('Product_Model_DbTable_ProdCategRelation');
}
class Product_Model_DbTable_Category extends Zend_Db_Table_Abstract
{
protected $_name = 'category';
protected $_dependentTables = array('Product_Model_DbTable_ProdCategRelation');
}
class Product_Model_DbTable_ProdCategRelation extends Zend_Db_Table_Abstract
{
protected $_name = 'product_category';
protected $_referenceMap = array(
'Product' => array(
'columns' => 'pid',
'refTableClass' => 'Product_Model_DbTable_Product',
'refColumns' => 'id'
),
'Category' => array(
'columns' => 'cid',
'refTableClass' => 'Product_Model_DbTable_Category',
'refColumns' => 'id'
)
);
}
还有我的实验控制器代码(或多或少可以工作,但方法似乎不正确;不妨回到普通表连接):
我是否可以仅通过实例化一个产品而不是全部产品来使用这些关系获取产品的类别?您可以使用这些关系。因此,您的代码可能会转换为:
$product = $productObj->fetchRow('id = 1');
$categoryInfo = $product->findManyToManyRowset(
'Product_Model_DbTable_Category',
'Product_Model_DbTable_ProdCategRelation'
)->current();
你可以为此目的使用。因此,您的代码可能会转换为:
$product = $productObj->fetchRow('id = 1');
$categoryInfo = $product->findManyToManyRowset(
'Product_Model_DbTable_Category',
'Product_Model_DbTable_ProdCategRelation'
)->current();
但是如果没有
current()
,它将只返回行集的第一行-我想,如果产品有多个类别,OP想要的就是所有这些。我假设我的$\u依赖项和$\u referenceMap
是正确的。@singlescurrent()
仅取自OP的原始代码。虽然我同意,产品-类别可能不是1:1的关系。但是如果没有current()
,它将只返回行集的第一行-我想,OP want就是它们的全部,如果该产品有多个类别。我假设我的$\u依赖项
和$\u引用映射
是正确的。@singlescurrent()
仅取自OP的原始代码。虽然我同意,但产品类别可能不是1:1的关系。