Replace model::find() function with model::query()

Dear All,

Its fun to use Yii . I would like to project a minor change.

We know model::find() return ActiveQuery object. So why this function name is find(). I think it can be safely renamed in future version as model::query().

Thats can also be adapted for Yii3.0


That was done so querying was like writing English sentences (a bit reversed but still):

$posts = Post::find()->where(['author_id' => 10])->all();
// post *find* where author_id is 10 *all*

Query would work as well. @vanhelvzla what do you think?

1 Like

We have also findOne, findAll, findBySql methods. Maybe findXXX is more expressive than queryXXX


Well, Idea was just for find() function not finalAll(). find() return ActiveQuery object . And finalAll() it return data array which is OK.

@samdark, I like find() too but query() would give hint that its returning ActiveQuery object and not data.

Its just minor improvement. We can have both find() and query() .

@fabriziocaldarelli has a point. Overall it is more consistent with find():

$posts = Post::find()->where(['author_id' => 10])->all();
$posts = Post::findAll(['author_id' => 10]);


$posts = Post::query()->where(['author_id' => 10])->all();
$posts = Post::findAll(['author_id' => 10]);
1 Like

Totally agree with @fabriziocaldarelli, i don’t think we should change the yii2 syntax if it is not necessary, it will be easier to migrate.

Thank you all.