Select Join Criteria Yii

I have 2 table

CREATE TABLE IF NOT EXISTS listings (

ListingId int(11) NOT NULL AUTO_INCREMENT,

Title varchar(255) NOT NULL,

ZoneId int(11) NOT NULL,

CityId int(11) NOT NULL,

PRIMARY KEY (ListingId),

KEY ZoneId (ZoneId,CityId),

KEY CityId (CityId)

)

CREATE TABLE IF NOT EXISTS zones (

ZoneId int(11) NOT NULL AUTO_INCREMENT,

Zone varchar(45) NOT NULL,

PRIMARY KEY (ZoneId)

)

i want get zones related with listings

SELECT * FROM listings l LEFT JOIN zones z ON l.zoneid = z.zoneid

This is my YII Criteria

         $Criteria=new CDbCriteria(); 


         $Criteria->select= '*';


        // $Criteria->together = true;   


         $Criteria->join= 'LEFT JOIN zones z ON l.zoneid = z.zoneid';


        $models = Listings::model()->findAll($Criteria);   

WAHT IS ERROR IN THIS

IMP : i using this on YII resful have any method if this

thank you YII

you must define relation in Listings model (in relations() function):




public function relations() {

        return array(

            'zones' => array( self::BELONGS_TO, 'Zone', 'zoneId' ),

        );

    }



(of course you need Zone model class to be created) and then write criteria like this:


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

no need to write ‘join’ clause by yourself as it will be added automatically by ‘with’.