开发者

Zend Framework Handle One to Many

I have 2 tables "user", "contact", the relation between two tables is one user has many contact

Table member 
m_id
name
------------
Table Contact
c_id
c_m_id
value

in zend model class, i do it in this way

/* 开发者_StackOverflow社区Member.php */
     class Default_Model_DbTable_Member extends Zend_Db_Table_Abstract
     {
        protected $_name    = 'member';
        protected $_dependentTables = array('Default_Model_DbTable_Contact');
     }

/* Contact.php */
     class Default_Model_DbTable_Contact extends Zend_Db_Table_Abstract
     {
        protected $_name = 'contact';
        protected $_referenceMap = array(
                           'Member' => array(
                                    'columns'=> array('c_id'),
                                    'refTableClass'=> 'Default_Model_DbTable_Member',
                                    'refColumns'=> array('c_m_id')
                                   )       
    );
/* IndexController.php */
class IndexController extends Zend_Controller_Action
{
    public function indexAction()
    {   
        $m= new Default_Model_DbTable_Member();
        $row = $m->find(1);
        $data = $row->current();
        $data = $data->findDependentRowset('Default_Model_DbTable_Contact');
        print_r($data->toArray());
     }
}

But i just get Invalid parameter number: no parameters were bound , my goal is to search a member detail record, and it also contains a array which store all contact info (i can use join method to do that, but i just want to try zend feature)


Have you tried defining

 class Default_Model_DbTable_Member extends Zend_Db_Table_Abstract
 {
    protected $_name    = 'member';
    protected $_primary = 'm_id';  <---


I've always put the $_dependentTables and $_referenceMap in both connected tables (Contact & Member). Did you try that?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜