Overriding ActiveQuery - Calling unknown method: yii\db\ActiveQuery::fechadas()

Hi!
I’m overriding ActiveQuery model AdmVeiculosSolictacoes.
I created this new method fechadas() but when I call it, I get the error “Calling unknown method: yii\db\ActiveQuery::fechadas()”.

What’s wrong?

AdmVeiculosSolicitacoesQuery.php

namespace app\models;

/**
 * This is the ActiveQuery class for [[AdmVeiculosSolicitacoes]].
 *
 * @see AdmVeiculosSolicitacoes
 */
class AdmVeiculosSolicitacoesQuery extends \yii\db\ActiveQuery
{
/*public function active()
{
    return $this->andWhere('[[status]]=1');
}*/

/**
 * {@inheritdoc}
 * @return AdmVeiculosSolicitacoes[]|array
 */
public function all($db = null)
{
    return parent::all($db);
}

/**
 * {@inheritdoc}
 * @return AdmVeiculosSolicitacoes|array|null
 */
public function one($db = null)
{
    return parent::one($db);
}

public function fechadas()
{
    return $this->andWhere(['or',['aprovado' => 0], ['devolvido' => 1]]);
}    
}

AdmVeiculosSolicitacoes.php

 public function getKmInicial()
    {
        $kmFinal_ultimaFechada = AdmVeiculosSolicitacoes::find('km_final')
                                                         ->where(['id_veiculo' => $this->id_veiculo])
                                                         ->fechadas() 
                                                         ->orderBy(['devolucao_confirmada_em' => SORT_DESC])
                                                         ->one();

        if ($kmFinal_ultimaFechada === null) {
            $veiculo = AdmVeiculos::findOne($this->id_veiculo);
            return $veiculo !== null ? $veiculo->km_atual : null;
        }
        else return $kmFinal_ultimaFechada['km_final'];
    }

You need to override this method to use different ActiveQuery object.

1 Like

That was it! Thank you for replying, Bizley!