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()

    {

        $t=$this->tableName();

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

    }




When I use relation:


$query = YZdocsStu::find();

$query->joinWith([

            'codeSpeciality',

        ], 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


andOnCondition

method: http://www.yiiframework.com/doc-2.0/yii-db-activequery.html#andOnCondition()-detail

Just like for there


where()

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