Usman Iqbal
Usman Iqbal

Reputation: 2429

How to write this join query in cdbcriteria?

I've been stuck for three hours and I cannot find a solution, I want to show only the name of those packages which are in the business_package table in my dropdown. My sql query which is working fine I do not know how to write in cdbcriteria, I tried to write in cdbcriteria, but I get error every time. Given below is my sql query.

select package.id
from package
join business_package on package.id = business_package.package_id 

I want to use the results in given below drop down list.

$this->widget('ext.select2.ESelect2',array(
  'name'=>'ReviewPackage[Package_id]',
  'data'=>CHtml::listData(Package::model()->findAll($criteria), 'id', 'package_name'), 
  //the whole available list of those package which are in business package table.
  'htmlOptions'=>array(
       'placeholder'=>' search Business name?',
    //'options'=>$options, //the selected values
   // 'multiple'=>'multiple',
    'style'=>'width:530px',
  ),
  ));

Upvotes: 1

Views: 89

Answers (1)

user5542121
user5542121

Reputation: 1052

See http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder

Something like that should do it:

$criteria = new CDbCriteria;
$criteria->alias = 'package';
$criteria->select = 'package.id';
$criteria->join='LEFT JOIN business_package ON business_package.package_id=package.id';

Upvotes: 2

Related Questions