Return Query Builder Sql To Activerecord Model


Anyone know how to return a ActiveRecord Object with a query builder sql?!

public static function get(){

   // 1.AR

   $result = Cms::model()->with('cmsFields')->findAll();


   // 2. Query builder 

   pages = Yii::app()->db->createCommand()

	    ->select('c.*, cf.*')

            ->from('cms c')

            ->join('cms_fields cf', ' = cf.id_cms')




    return $result;


How to return query 2 like query 1? It’s way for that?


You can use


to do that. It is basically what CActiveRecord does anyway.

Hello Dave,

Thanks… In that away i can use Query Builder, which i like very much, and my other partner, uses activeRecord :)

I put this technic on test and see it performance.

Thanks :)