php - Yii sql generation -
i trying prepare following sql query unfortunately did not work.
select course.course_name, enroll.start_date dp_courses course left outer join dp_enroll enroll on course.id = enroll.course_id , enroll.student_id=3 $criteria=new cdbcriteria(array( 'order'=>'update_time desc', 'with'=> array('enroll'), )); $criteria->alias = 'course'; $criteria->together=true; $criteria->join='left outer join dp_enroll on dp_enroll.course_id=course.id , dp_enroll.student_id='. yii::app()->user->id; //$criteria->condition='dp_enroll.student_id='. yii::app()->user->id;
relation in course model is:
public function relations() { return array( 'enroll'=> array(self::has_many, 'enroll', 'course_id'), 'author' => array(self::belongs_to, 'yumprofile', 'author_id'), ); }
but resulting sql query want
left outer join dp_enroll enroll on course.id = enroll.course_id **and** enroll.student_id=3
joining tables on 2 attribute and operator
it in docs, point 1 declaring relationship. yii not have idea composite join in example. if want join this, have define composite key relation, instad course_id
define array stated in docs:
array('fk_c1'=>'pk_c1','fk_c2'=>'pk_c2')
Comments
Post a Comment