combine two table into one table

Hi, I confused what the suitable title for this questions.

I have two table ( Content and Content_Detail)

this table is use for multilanguage Content.

each I will grab the content I always use this command:




$model = Content::model()->with('Content_Detail')->findAll("Content_Detail.lang = :lang", array(":lang" => Yii::app()->language 

))

yes this way is correct, but I feel tired if each I need to grab the content I have to use this way. this way is too long and not efisien I think.

are there are any way to use like this script above that more simple?

Yes you can define a default scope or a scope and use those instead of applying it to each query.

See

http://www.yiiframework.com/doc/api/CActiveRecord#defaultScope-detail

http://www.yiiframework.com/doc/api/CActiveRecord#scopes-detail

hi sir, thanks for reply.

can you give me an example to use with() in defaultScope sir ?

hi sir, I have try this




    public function defaultScope(){

        $criteria = new CDbCriteria();

        $criteria->with = array('ContentD');

        $criteria->condition = "ContentD.lang = :lang";

        $criteria->params = array(':lang' => Yii::app()->language );

        return $criteria;

    }



but there are error,




CDbException

Description

CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ContentD.lang' in 'where clause'



and the "with" criteria is not work. becuase the query that resulted by the defaultScope() is




rror in querying SQL: SELECT COUNT(*) FROM `tsite_Content` `t` WHERE

(ContentD.lang = :lang) AND (parent_id = :parent_id)



oh my god!! very confused! please help me sir!