それぞれに独自のマッパーがあります。
Product_Model_DbTable_Product
Product_Model_DbTable_Category
Product_Model_DbTable_ProdCategRelation
私はそれがどのように行われるかについていくつかの チュートリアルを見ましたが、それでも私はそれを理解していません。
これは私が現在持っているものです:
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'
)
);
}
そして、私の実験的なコントローラーコード(多かれ少なかれ機能していますが、メソッドは正しくないようです。プレーンなテーブル結合に戻ることもできます):
public function indexAction()
{
$productObj = new Product_Model_DbTable_Product;
$categoryObj = new Product_Model_DbTable_Category();
$product = $productObj->fetchRow('id = 1');
$productRelation = $product->findDependentRowset('Product_Model_DbTable_ProdCategRelation', 'Product')->current();
$category = $categoryObj->fetchRow('id = ' . $productRelation->cid);
$categoryInfo = $category->findDependentRowset('Product_Model_DbTable_ProdCategRelation', 'Category')->current();
}
全体ではなく、製品をインスタンス化するだけでこれらの関係を使用して製品のカテゴリを取得できますか?