Order by Field Type SET

public function getAgenteEnderecoPrincipal()


    /*return $this->hasOne(AgenteEndereco::className(), ['agente_id' => 'id'])


    return $this->hasOne(AgenteEndereco::className(), ['agente_id' => 'id'])

            ->orderBy("FIELD( tipo, 'Correspondência')");


but the query is generated as follows:

ERROR: SELECT * FROM agente_endereco WHERE agente_id=2351 [color="#FF0000"]ORDER BY FIELD( tipo, 'Correspondência')[/color]

to work would be correct:

SELECT * FROM sjnew_beta.agente_endereco [color="#006400"]ORDER BY FIELD( tipo, ‘Correspondência’, ‘Cobrança’)[/color]

*Attention to the quotes

Can someone help me?

You can use class Expression


See also conversation: https://github.com/yiisoft/yii2/issues/553