Does anyone know if there is a way to have a default scope AND an ActiveQuery for an ActiveRecord. Or maybe I’m looking at this the wrong way for Yii2.
I have a project where all of the data is keyed off of the user_id. So I don’t want to have to keep adding the where "customer_id = " clause to every single query. In Yii 1.0 there was the concept of a default scope.
But how would I go about using the default scope AND and ActiveQuery class. Ex:
<?php
namespace app\models;
use yii\db\ActiveQuery;
class AuditionQuery extends ActiveQuery
{
public function booked()
{
$this->andWhere('audition_id in (select audition_id from booking where customer_id = '.
Yii::app()->request->cookies['customer_id']->value).')');
return $this;
}
}
?>
@Gerhard of course you can do all that in yii2 as well, its easy to port your 1 code 2, I used yii2 for a insurance system recently no issues at all and speed is not that bad