active-record icon indicating copy to clipboard operation
active-record copied to clipboard

The method allPopulate in ActiveQuery will execute populate twice during execution

Open niqingyang opened this issue 5 months ago • 0 comments

What steps will reproduce the problem?

The method allPopulate in ActiveQuery will execute populate twice during execution.

Is this how it was designed or is it a bug ?

   public function all(): array
    {
        if ($this->shouldEmulateExecution()) {
            return [];
        }

        return $this->populate($this->createCommand()->queryAll(), $this->indexBy); // Repeated execution
    }

    public function allPopulate(): array
    {
        $rows = $this->all();

        if ($rows !== []) {
            $rows = $this->populate($rows, $this->indexBy); // Repeated execution
        }

        return $rows;
    }

What is the expected result?

populate should only be executed once ?

What do you get instead?

populate executed twice

Additional info

Q A
Version 1.0.?
PHP version 8.1
Operating system windows 10

niqingyang avatar Jan 04 '24 05:01 niqingyang