OmgDef / yii2-multilingual-behavior

Yii2 port of the yii-multilingual-behavior.
146 stars 60 forks source link

Custom Scopes #20

Closed andreCatita closed 9 years ago

andreCatita commented 9 years ago

Hello again @OmgDef,

How do you handle Custom Scoping, with your MultlingualBehavior? Do we at all?

Example:

Products::find()->visible()->all();

and usually I create a ProductsQuery with the function below:

protected function visible() {
     $this->andWhere('is_visible = 1');
     return $this;
}

But I need to overwrite find() in my Model to something like:

          return new ProductsQuery(get_called_class());

The obvious and current problem is:

Calling unknown method: multilingual\MultilingualQuery::visible()

is there anyway to apply Custom Scoping, and use the MultilingualBehavior across multiple Models?

padlyuck commented 9 years ago
namespace app\models;

use yii\db\ActiveQuery;

class ProductsQuery extends ActiveQuery
{
    use MultilingualTrait;
    public function visible(){
// ...
    }
}
padlyuck commented 9 years ago

@andreCatita see in the end of file https://github.com/OmgDef/yii2-multilingual-behavior/blob/master/README.md

andreCatita commented 9 years ago

Thanks. Didn't pay close attention.