Zend_Db and dependentRows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Zend_Db and dependentRows

Post by jamiel »

Hey all,

I am trying to use the dependantRowSet functionality of Zend_Db in order to retrieve a Rowset from a second table liked by a foreign key constraint.

Below is some test code which I have knocked up to achieve this, but Zend_Db is throwing an Exception of 'No reference from table Image to table ImageGallery' . This seems like quite a trivial operation so I'm sure I have just missed something elementary.

Code: Select all

class Image extends Zend_Db_Table_Abstract
   {
       protected $_name = 'dbname.image';
       protected $_primary = 'id';
       protected $_dependentTables = array('ImageGallery');
    }

class ImageGallery extends Zend_Db_Table_Abstract
   {
       protected $_name         = 'dbname.image_gallery';
       protected $_primary      = 'id';
       protected $_referenceMap = array(
           'Image' => array(
               'columns' => 'image_id',
               'refTableClass' => 'Image',
               'refColumns' => 'id'),
           'Section' => array(
               'columns' => 'section_id',
               'refTableClass' => 'Section',
               'refColumns' => 'id'),
           'Subsection' => array(
               'columns' => 'subsection_id',
               'refTableClass' => 'Subsection',
               'refColumns' => 'id')
           );

       public static function getSectionImageCount($sectionName)
       {
           $gallery = new ImageGallery();
           $galleryImageRs = $gallery->find(1);
           $galleryImage = $galleryImageRs->current();
           Zend_Debug::dump($galleryImage->findDependentRowset('Image'));
       }
   }
Exception occurs when calling getSectionImageCount() from my controller.
Post Reply