View Single Post
  #1 (permalink)  
Old 06-05-2008, 11:01 PM
fiskah fiskah is offline
Junior Member
 
Join Date: Mar 2008
Posts: 2
Default No reference from table X to table Y.

I have a simple hierarchy category layout (two layers), and in the bottom layer there is a number of channels. What I want to do is fetch all top categories (where parent = null), and then for each fetch the child categories. For each child category I need the channels in that one.

Problem is that I get an exception:
Quote:
'Zend_Db_Table_Exception' with message 'No reference from table Simple_Channel to table Simple_Channel_Category'
I take it its the reference maps thats wrong, but I can't spot the error. Can anyone help me out?

Code:

Simple_Channel_Category:
PHP Code:

class Simple_Channel_Category extends Simple_Core_Database_Table
{
    protected 
$_dependentTables = array('simple_channel''simple_channel_category');
    protected 
$_primary 'category_id'
    protected 
$_referenceMap = array(
        
'Children' => array(
            
'refTableClass' => 'Simple_Channel_Category',
            
'columns' => 'parent'
        
),
        
'Channel' => array(
            
'refTableClass' => 'simple_channel',
            
'columns' => 'category_id',
            
'refColumns' => 'id'
        
)
    );
    
    function 
getTopCategories()
    {
        return 
$this->fetchAll($this->select()->where('parent is null'));
    }

Simple_Channel:
PHP Code:
class Simple_Channel extends Simple_Core_Database_Table
{
    
// Zend_Db_Table implementation
    
protected $_name 'simple_channel';
    protected 
$_primary 'channel_id';
    protected 
$_dependentTables = array('simple_channel_category');
    protected 
$_referenceMap = array(
        
'simple_category' => array(
            
'refTableClass' => 'simple_channel_category',
            
'refTable' => 'Simple_Channel_Category',
            
'columns' => 'id'
        
)
    );

Controller:
PHP Code:
$category = new Simple_Channel_Category();

foreach(
$category->getTopCategories() as $category)
{
    echo 
$category->name.'<br />';
    foreach(
$category->findDependentRowset('simple_channel_category') as $sub)
    {
        echo 
'&nbsp;&nbsp;'$sub->category_id ' ' $sub->name ' (' get_class($sub) . ')<br />';
    
        foreach(
$sub->findDependentRowset('simple_channel') as $c)
        {
            echo 
'!!' $c->name.'<br/>';
        }
    }

Reply With Quote