views:

54

answers:

2

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

/* 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)

A: 

Have you tried defining

 class Default_Model_DbTable_Member extends Zend_Db_Table_Abstract
 {
    protected $_name    = 'member';
    protected $_primary = 'm_id';  <---
Kevin Schroeder
actually im using "id" instead of "m_id", using "m_id" here is just for clear my question
A: 

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

chelmertz
haha. i know what u mean, but i think it will only allow 1 to 1, but not 1 to many?