php - Getting full join by cdbcriteria yii, mysql db? -
using cdbcriteria class of yii how can full join(db mysql)? know can achieved through union of left join , right join.....but syntex not getting
$criteria = new cdbcriteria; $criteria->with = array( 'posts' => array( 'jointype' => 'inner join', 'together' => true, ), ); $models = user::model()->findall($criteria); foreach($models $model) { echo $model->username;// gives username foreach($model->posts $post) { echo $post->title; // gives post title } } // if it's 1 user: $criteria = new cdbcriteria; $criteria->addcondition('user_id', (int)$user_id); $criteria->with = array( 'posts' => array('together' => true, 'jointype' => 'inner join'), ); $model = user::model()->find($crieteria); echo $model->username; foreach ($model->posts $post) { echo $post->title; } // can: $model = user::model()->with('posts')->findbypk((int)$user_id); echo $model->username; foreach($model->posts $post) { echo $post->title; } in above example assume have user table has one:many relation posts table , posts relation defined in relations() method of yii ar.
Comments
Post a Comment