public function getFields($table = null, $ignoreAI = false)
    {
        if ($this->fields === null) {
            $table = $table ?: $this->table;

            $this->fields = $this->db->getTable($table)->getColumnDetails();
        }

        $fields = [];

        foreach ($this->fields as $field) {
            if ($ignoreAI && $field->Extra === 'auto_increment') {
                continue;
            }

            if (strtolower($field->Null) === 'no' && $field->Default === null
                && $field->Key !== 'PRI' && $this->getKeyName() !== $field->Field) {
                $type = $field->Type;

                list($type,) = explode('(', $type, 2);
                $type = strtolower($type);

                $field->Default = $this->db->getTable($table)->getDataType()->getDefaultValue($type);
            }

            $field = (object) $field;
            $fields[$field->Field] = $field;
        }

        return $fields;
    }