[Solar-talk] where select in related tables

Raymond Kolbe rkolbe at gmail.com
Wed Dec 5 09:11:32 CST 2007


$params = array(
       'where'  => array(
           'articalcat.sub_cat_name = ?' => $category,
       ),
   );

This should be:

$params = array(
    'eager' => 'articalcat',
    'where'  => array(
           'articalcat.sub_cat_name = ?' => $category,
       ),
   );



On Dec 5, 2007 1:30 AM, Jeff Surgeson <solar at 3hex.com> wrote:

> Hi All
>
> I am battling to get a where clause to work in a query when the where
> clause
> is based on a related table.
>
> I have two tables, an artical table with related category table.
>
> #############################
> $this->_table_name = 'articals';
>
> $this->_table_cols = array(
>    'id' => array(
>        'type'    => 'int',
>        'require' => true,
>        'primary' => true,
>        'autoinc' => true,
>    ),
>    'title' => array(
>        'type'    => 'varchar',
>        'size'    => 255,
>    ),
>    'description' => 'clob',
>    'main_cat' => array(
>        'type'    => 'int',
>    ),
> );
>
> $this->_hasOne('articalcat', array(
>    'foreign_class' => 'ArticalCat',
>    'native_col'    => 'main_cat',
>    'foreign_col'   => 'id',
> ));
>
> ###########################
> $this->_table_name = 'articalcat';
>
> $this->_table_cols = array(
>    'id' => array(
>        'type'    => 'int',
>        'require' => true,
>        'primary' => true,
>        'autoinc' => true,
>    ),
>    'main_cat_name' => array(
>        'type'    => 'varchar',
>        'size'    => 255,
>        'require' => true,
>    ),
>    'sub_cat_name' => array(
>        'type'    => 'varchar',
>        'size'    => 255,
>        'require' => true,
>    ),
> );
>
> $this->_belongsTo('articals', array(
>    'foreign_class' => 'Articals',
>    'foreign_col'   => 'main_cat',
>    'native_col'    => 'id',
> ));
>
>
> ############################
> $this->_articals = Solar::factory('Bulldog_Model_Articals');
>
> public function actionList($category)
> {
>    $params = array(
>        'where'  => array(
>            'articalcat.sub_cat_name = ?' => $category,
>        ),
>    );
>
>    // get the list and assign to view
>    $this->list = $this->_articals->fetchAll($params);
>
> }
>
> I know that the relationships between the table are working, because
> without
> the above where clause
>
> foreach ($this->list as $item) {
>    echo $item->articalcat->main_cat_name;
> }
>
> in my view produces correct results.
>
> How do I specify a where clause based on the related category table.
> $category passed to actionList() is \'Using the Sun\' which is a
> sub_cat_name
> field.
>
> --
> ...........::::::...........
> Jeff Surgeson / South Africa
> _______________________________________________
> Solar-talk mailing list
> Solar-talk at lists.solarphp.com
> http://mailman-mail3.webfaction.com/listinfo/solar-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman-mail3.webfaction.com/pipermail/solar-talk/attachments/20071205/9d3e45e6/attachment.html


More information about the Solar-talk mailing list