如何使用Zend_Db_Table与多对多关系

时间:2012-08-07 13:23:20

标签: php zend-framework many-to-many relational-database

如何使用带有Zend_Db_Table的Zend many to many relationships和联结表?是否存在提供此虚构性的内置方法或必须编写简单的SQL?

1 个答案:

答案 0 :(得分:0)

它在文档中:Fetching a Rowset via a Many-to-many Relationship

要获取一行:

$row->findManyToManyRowset($table,
                           $intersectionTable,
                           [$rule1,
                               [$rule2,
                                   [Zend_Db_Table_Select $select]
                               ]
                           ]);
// Example
$productsRowset = $bug1234->findManyToManyRowset('Products',
                                                 'BugsProducts');
// Here, BugsProducts is the junction table

但是,对于一对多关系,您还需要在类中定义关系:Defining relationships