How to define relationships in Zend Framework

I have two simple tables: Projectsand SubProjects, which I would like to print each subproject with the corresponding project in the 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 would like to know why I get No reference from table Admin_Model_SubProjects to table Admin_Model_Projectson typing<?php echo $entry->findParentRow('Admin_Model_Projects'); ?>

+3
source share
2 answers

It looks like you are missing the rule name in the definition referenceMap.
It should be

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

You must define $_referenceMapand $_dependentTablesall related table classes. When you are done, it will be close to mirroring.

0
source

Source: https://habr.com/ru/post/1765686/


All Articles