vendredi 4 juillet 2014

Active Query in Yii2?


Vote count:

0




I have 2 tables:


Auto


id (pk) int


name varchar100


color int


AutoComparison


auto1_id


auto2_id


status


Where:


(*status - id 0 new


id 1 old


id 2 broken)


I need to select all cars whose status (1 "broken") and count the number of them.


Model Auto.php



public function getAutos($status)
{
return $this->hasMany(AutoComparison::className(), ['auto1_id' => 'id'])
->where('status > :status', [':status' => $status])
->orderBy(['id' => SORT_ASC]);
}

public function getNumberAutos()
{
return $this->getAutos()->count();
}


The question that I need to change in the model and insert into the view file (template.php), in order to display the number of broken auto's. (Framework Yii2)



asked 2 mins ago






Aucun commentaire:

Enregistrer un commentaire