如何在 Zend Framework 中定义关系
我有两个简单的表:Projects
和 SubProjects
,我想在表中打印每个子项目以及相应的项目。
所以我写了这个:
class Admin_Model_Projects extends Zend_Db_Table_Abstract
{
protected $_name = 'main_projects';
protected $_primary = 'mai_id';
protected $_sequence = true;
protected $_dependentTables = array('Admin_Model_SubProjects');
....
还有这个:
class Admin_Model_SubProjects extends Zend_Db_Table_Abstract
{
protected $_name = 'sub_projects';
protected $_primary = 'sub_id';
protected $_sequence = true;
protected $_referenceMap = array(
'columns' => 'mai_id',
'refTableClass' => 'Admin_Model_Projects',
'refColumns' => 'mai_id'
);
.....
我想知道为什么当我输入 findParentRow 时,我会得到
No reference from table Admin_Model_SubProjects to table Admin_Model_Projects
('Admin_Model_Projects'); ?>
I have two simple tables: Projects
and SubProjects
which I'd like to print every subproject with the respective project in a table.
So I wrote this:
class Admin_Model_Projects extends Zend_Db_Table_Abstract
{
protected $_name = 'main_projects';
protected $_primary = 'mai_id';
protected $_sequence = true;
protected $_dependentTables = array('Admin_Model_SubProjects');
....
And this:
class Admin_Model_SubProjects extends Zend_Db_Table_Abstract
{
protected $_name = 'sub_projects';
protected $_primary = 'sub_id';
protected $_sequence = true;
protected $_referenceMap = array(
'columns' => 'mai_id',
'refTableClass' => 'Admin_Model_Projects',
'refColumns' => 'mai_id'
);
.....
I'd like to know why do I get No reference from table Admin_Model_SubProjects to table Admin_Model_Projects
when I type <?php echo $entry->findParentRow('Admin_Model_Projects'); ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
referenceMap
定义中似乎缺少规则名称。应该是
Looks like you're missing name of the rule in your
referenceMap
definition.It should be
您应该在所有相关的表类中定义
$_referenceMap
和$_dependentTables
。完成后,它看起来几乎是镜像的。You should define
$_referenceMap
and$_dependentTables
in all of the related table-classes. It will look close-to mirrored when you're done.