why in this function we transform data instance of RowObjectInterface to
array? Not only ResultSet object? That we remove advantage of object access
in View (like echo $row->id).


code:
    /**
     * Cast result set to array of arrays
     * 
     * @return array
     * @throws Exception\RuntimeException if any row is not castable to an
array
     */
    public function toArray()
    {
        $return = array();
        foreach ($this as $row) {
            if (is_array($row)) {
                $return[] = $row;
            } elseif (method_exists($row, 'toArray')) {
                $return[] = $row->toArray();
            } elseif ($row instanceof ArrayObject) {
                $return[] = $row->getArrayCopy();
            } else {
                throw new Exception\RuntimeException('Rows as part of this
datasource cannot be cast to an array');
            }
        }
        return $return;
    }


I guess it should be loop without transforming RowObject to array access
only:

    public function toArray()
    {
        $return = array();
        foreach ($this as $row) {
            if ($row instanceof RowObjectInterface) {
                $return[] = $row;
            } elseif (method_exists($row, 'toArray')) {
                $return[] = $row->toArray();
            } else {
                throw new Exception\RuntimeException('Rows as part of this
datasource cannot be cast to an array');
            }
        }
        return $return;
    }


I tested, it don't emit "mysql out of sync error" too. Otherwise we should
create additional function to avoid  "mysql out of sync error".

--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZF2-Db-ResultSet-toArray-algoritm-tp4505005p4505005.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to