0

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'];
    }

1 Answer 1

1

Have you updated your AdmVeiculosSolicitacoes class to use the new Query?

https://www.yiiframework.com/doc/guide/2.0/en/db-active-record#customizing-query-classes

class AdmVeiculosSolicitacoes extends ActiveRecord
{
    public static function find()
    {
        return new AdmVeiculosSolicitacoesQuery(get_called_class());
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.