Zend 一对多不起作用

发布于 2024-12-03 20:09:04 字数 2148 浏览 0 评论 0原文

我正在尝试 zend 框架中一对多关系的示例,但我无法得到结果。

以下是表格:

UsersTable:

<?php

class Application_Model_DbTable_UsersTable extends Zend_Db_Table_Abstract
{

    protected $_name = 'users';
    protected $_dependentTables = array('Application_Model_DbTable_BugsTable');

}

BugsTable:

class Application_Model_DbTable_BugsTable extends Zend_Db_Table_Abstract
{
    protected $_name = 'bugs';

    protected $_dependentTables = array('Application_Model_DbTable_BugsProductsTable');

    protected $_referenceMap    = array(
        'Reporter' => array(
            'columns'           => 'reported_by',
            'refTableClass'     => 'Application_Model_DbTable_UsersTable',
            'refColumns'        => 'username'
        ),
        'Engineer' => array(
            'columns'           => 'assigned_to',
            'refTableClass'     => 'Application_Model_DbTable_UsersTable',
            'refColumns'        => 'username'
        ),
        'Verifier' => array(
            'columns'           => array('verified_by'),
            'refTableClass'     => 'Application_Model_DbTable_UsersTable',
            'refColumns'        => array('username')
        )
        );

}

正如您所看到的,这是从数据库表“users”到表“bugs”的一对多关系,其中 bugs talbe 中有三个外来引用键。

现在,当我尝试对一对多关系使用 Zend 方法时,我总是得到空结果:

    $tableUser = new Application_Model_DbTable_UsersTable();
    $tableBugs = new Application_Model_DbTable_BugsTable();

    $result= $tableUser->find(1);
    $user= $result->current();
    $userBugs = $user->findDependentRowset('Application_Model_DbTable_BugsTable','Verifier');
    echo count($userBugs);  //returns 0

    $bugresult = $tableBugs->find(1);
    $thisbug= $bugresult->current();

    $verifier= $thisbug->findParentRow('Application_Model_DbTable_UsersTable','Verifier');
    return $verifier //returns nothing

正确的数据在数据库中,例如,当我执行查询时:

select * from bugs b, users u where b.reported_by=u.id and u.id=1;

我得到预期的结果。但是当我在 zend 中尝试时没有结果。 您有什么建议吗?谢谢。

I was trying an example of one to many relationship in zend framework, but I can't get results.

Here are the tables:

UsersTable:

<?php

class Application_Model_DbTable_UsersTable extends Zend_Db_Table_Abstract
{

    protected $_name = 'users';
    protected $_dependentTables = array('Application_Model_DbTable_BugsTable');

}

BugsTable:

class Application_Model_DbTable_BugsTable extends Zend_Db_Table_Abstract
{
    protected $_name = 'bugs';

    protected $_dependentTables = array('Application_Model_DbTable_BugsProductsTable');

    protected $_referenceMap    = array(
        'Reporter' => array(
            'columns'           => 'reported_by',
            'refTableClass'     => 'Application_Model_DbTable_UsersTable',
            'refColumns'        => 'username'
        ),
        'Engineer' => array(
            'columns'           => 'assigned_to',
            'refTableClass'     => 'Application_Model_DbTable_UsersTable',
            'refColumns'        => 'username'
        ),
        'Verifier' => array(
            'columns'           => array('verified_by'),
            'refTableClass'     => 'Application_Model_DbTable_UsersTable',
            'refColumns'        => array('username')
        )
        );

}

As you can see, this is one to many relationship from db table 'users' to table 'bugs' , where we have three foreign reference keys in bugs talbe.

Now when I try to use Zend methods for one to many relationships I always get empty results:

    $tableUser = new Application_Model_DbTable_UsersTable();
    $tableBugs = new Application_Model_DbTable_BugsTable();

    $result= $tableUser->find(1);
    $user= $result->current();
    $userBugs = $user->findDependentRowset('Application_Model_DbTable_BugsTable','Verifier');
    echo count($userBugs);  //returns 0

    $bugresult = $tableBugs->find(1);
    $thisbug= $bugresult->current();

    $verifier= $thisbug->findParentRow('Application_Model_DbTable_UsersTable','Verifier');
    return $verifier //returns nothing

The proper data is in the database, when I for example do a query:

select * from bugs b, users u where b.reported_by=u.id and u.id=1;

I get the expected results. But when I try in zend no results.
Do you have any suggestions? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

难以启齿的温柔 2024-12-10 20:09:04

在你的sql中你会按字段得到错误

reported_id

但在这段代码中:

$result= $tableUser->find(1);
$user= $result->current();
$userBugs = $user->findDependentRowset('Application_Model_DbTable_BugsTable','Verifier');
echo count($userBugs);  //returns 0

$bugresult = $tableBugs->find(1);
$thisbug= $bugresult->current();

$verifier= $thisbug->findParentRow('Application_Model_DbTable_UsersTable','Verifier');
return $verifier //returns nothing

你尝试通过以下方式获取错误

验证者

字段

试试这个:

$result= $tableUser->find(1);
$user= $result->current();
$userBugs = $user->findDependentRowset('Application_Model_DbTable_BugsTable','Reporter');
echo count($userBugs);

In your sql u get bugs by field

reported_id

but in this code:

$result= $tableUser->find(1);
$user= $result->current();
$userBugs = $user->findDependentRowset('Application_Model_DbTable_BugsTable','Verifier');
echo count($userBugs);  //returns 0

$bugresult = $tableBugs->find(1);
$thisbug= $bugresult->current();

$verifier= $thisbug->findParentRow('Application_Model_DbTable_UsersTable','Verifier');
return $verifier //returns nothing

u try to get bug by

verified_by

field

try this:

$result= $tableUser->find(1);
$user= $result->current();
$userBugs = $user->findDependentRowset('Application_Model_DbTable_BugsTable','Reporter');
echo count($userBugs);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文