MySQL function in relations

Hi All,

I want to make relation with two tables but want use mysql function like this:

class YZdocsStu extends \yii\db\ActiveRecord



     * @inheritdoc


    public static function tableName()


        return 'y_zdocs_stu';



public function getCodeSpeciality()



        return $this->hasOne(CodeSpeciality::className(),['speciality_id' =>     "SUBSTRING_INDEX($t.speciality_code,'_',1)"]);


When I use relation:

$query = YZdocsStu::find();



        ], false, 'INNER JOIN');

I receive sql like this:

INNER JOIN `code_speciality` ON `y_zdocs_stu`.[[SUBSTRING_INDEX(y_zdocs_stu.speciality_code,'_',1)]] = `code_speciality`.`speciality_id`

That is wrong I need receive

INNER JOIN `code_speciality` ON SUBSTRING_INDEX(y_zdocs_stu.speciality_code,'_',1) = `code_speciality`.`speciality_id`

Any suggestion ?

Thank you

Check out the



Just like for there


method, you should be able to specify a condition exactly as you entered it.