如何在 Zend Framework 中定义关系

发布于 2024-09-24 04:47:24 字数 965 浏览 7 评论 0原文

我有两个简单的表:ProjectsSubProjects,我想在表中打印每个子项目以及相应的项目。

所以我写了这个:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

维持三分热 2024-10-01 04:47:25

您的 referenceMap 定义中似乎缺少规则名称。
应该是

protected $_referenceMap = array(
    'Project' => array(
        'columns' => 'mai_id',
        'refTableClass' => 'Admin_Model_Projects',
        'refColumns' => 'mai_id'
    )
);

Looks like you're missing name of the rule in your referenceMap definition.
It should be

protected $_referenceMap = array(
    'Project' => array(
        'columns' => 'mai_id',
        'refTableClass' => 'Admin_Model_Projects',
        'refColumns' => 'mai_id'
    )
);
不忘初心 2024-10-01 04:47:25

您应该在所有相关的表类中定义 $_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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文