In fact, you cannot completely write this, since you need to apply the criteria to the activerecord model to get the primary table, but provided that you have the DocDocs model, you can do it this way:
$oDBC = new CDbCriteria(); $oDBC->join = 'LEFT JOIN doc_access a ON t.id = a.doc_id and a.user_id = 7'; $aRecords = DocDocs::model()->findAll($oDBC);
Although this can be much simpler if you give your DocDocs model a relationship with doc_access, then you do not need to use dbcriteria:
class DocDocs extends CActiveRecord { ... public function relations() { return array('access' => array(self::HAS_MANY, 'DocAccess', 'doc_id'); } ... } $oDocDocs = new DocDocs; $oDocDocs->id = 7; $aRecords = $oDocDocs->access;
Should give you a good idea how to get started ...
Blizz
source share