[Solar-talk] problem with related tables with latest svn

Jeff Surgeson solar at 3hex.com
Sat Apr 12 06:45:22 CDT 2008


Hi All

I am having a problem getting related sql table stuff to work with latest svn, 
do I need to do something differant now to get related tables to work, what I 
am doing works with slightly older svn versions.

This is what I am trying to do, simple table to store image file names and a 
related category table.

My Data Models:

class Bulldog_Model_Gallery extends Solar_Model {

    protected $_Bulldog_Model_Gallery = array(
        'gallerycat' => 'Bulldog_Model_GalleryCat',
    );

    protected function _setup()
    {
        $this->_table_name = 'gallery';
        $this->_table_cols = array(
            'id'        => array(
                'type'          => 'int',
                'require'       => true,
                'primary'       => true,
                'autoinc'       => true,
            ),
            'image' => array(
                'type'    => 'varchar',
                'size'    => 255,
            ),
            'main_cat' => array(
                'type'    => 'int',
            ),
        );
        $this->_index = array('main_cat',);
        $this->_hasOne('gallerycat', array(
            'foreign_class' => 'GalleryCat',
            'native_col'    => 'main_cat',
            'foreign_col'   => 'id',
        ));
    }
}

class Bulldog_Model_GalleryCat extends Solar_Model {
    protected function _setup()
    {
        $this->_table_name = 'gallerycat';
        $this->_table_cols = array(
            'id' => array(
                'type'    => 'int',
                'require' => true,
                'primary' => true,
                'autoinc' => true,
            ),
            'main_cat_name' => array(
                'type'    => 'varchar',
                'size'    => 255,
            ),
            'sub_cat_name' => array(
                'type'    => 'varchar',
                'size'    => 255,
            ),
        );
        $this->_index = array('main_cat_name', 'sub_cat_name');
        $this->_belongsTo('gallery', array(
            'foreign_class' => 'Gallery',
            'foreign_col'   => 'main_cat',
            'native_col'    => 'id',
        ));
    }
}

My App Action:

public function actionList($category = null)
{
    $params = array(
        'eager'  => 'gallerycat',
        'where'  => array(
            'gallerycat.sub_cat_name = ?' => $category,
        ),
        'order'         => $this->_getSqlOrder(),
        'page'          => $this->_query('page', 1),
        'paging'        => $this->_query('paging', 2),
        'count_pages'   => true,
    );
    $this->list = $this->_gallery->fetchAll($params);
}

It generates this sql error which I dont know why as 

exception 'Solar_Sql_Adapter_Exception_QueryFailed'
class::code 'Solar_Sql_Adapter_Mysql::ERR_QUERY_FAILED' 
with message 'ERR_QUERY_FAILED' 
information array (
  'pdo_code' => '42S22',
  'pdo_text' => 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 
\'gallerycat.sub_cat_name\' in \'where clause\'',
  'host' => '127.0.0.1',
  'port' => NULL,
  'user' => 'root',
  'name' => 'outriders_db',
  'stmt' => 'SELECT
	COUNT(gallery.id)
	FROM gallery
	WHERE
		gallerycat.sub_cat_name = \'bike images\'
	LIMIT 1',
  	'data' => 
  		array (
    		'' => NULL,
  	),

I cant see why this wont work :-(

-- 
...........::::::...........
Jeff Surgeson / South Africa


More information about the Solar-talk mailing list