Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Conversation

@aywan
Copy link

@aywan aywan commented Aug 24, 2022

Without this have troubles when inherit Query object.
Don't know how write tests)

@gwynbox
Copy link
Collaborator

gwynbox commented Nov 3, 2022

Please can you provide an example of the issue encountered without adding $db to one() and all()

@aywan
Copy link
Author

aywan commented Mar 13, 2023

I usually override ActiveRecord::find with concrete class. It useful for typing.

<?php
/**
 * @method array|Profile              one($db = null)
 * @method array|Profile[]            all($db = null)
 * @method array|\Generator|Profile[] each($batchSize = 100, $db = null)
 */
class ProfileActiveQuery extends ActiveQuery
{
    public function __construct(array $config = [])
    {
        parent::__construct(Profile::class, $config);
    }
}

For example when id do $profiles = Profile::find()->where(...)->all() - everyone tool know $profiles is Profile[] type.

Inside Yii2 sources - interface also has $db attribute in this methods https://github.com/yiisoft/yii2/blob/master/framework/db/ActiveQueryInterface.php#L40

@GeorgeCadwallader GeorgeCadwallader removed their request for review October 16, 2023 15:04
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants