Browse Source

Make Query::addDefaultTypes() do what it says.

Instead of adding, addDefaultTypes() was replacing. While this is
useful, adding is more useful as we want the typemap to accumulate type
information throughout its lifetime.
mark_story 10 years ago
parent
commit
2400cf283c
2 changed files with 19 additions and 2 deletions
  1. 18 1
      src/Database/TypeMap.php
  2. 1 1
      src/ORM/Query.php

+ 18 - 1
src/Database/TypeMap.php

@@ -64,6 +64,8 @@ class TypeMap
      * $query->defaults(['created' => 'datetime', 'is_visible' => 'boolean']);
      * ```
      *
+     * This method will replace all the existing type maps with the ones provided.
+     *
      * @param array $defaults associative array where keys are field names and values
      * are the correspondent type.
      * @return $this|array
@@ -78,7 +80,20 @@ class TypeMap
     }
 
     /**
-     * Configures a map of fields and their associated types for single-use.
+     * Add additional default types into the type map.
+     *
+     * If a key already exists it will not be overwritten.
+     *
+     * @param array $types The additional types to add.
+     * @return void
+     */
+    public function addDefaults(array $types)
+    {
+        $this->_defaults = $this->_defaults + $types;
+    }
+
+    /**
+     * Sets a map of fields and their associated types for single-use.
      *
      * If called with no arguments it will return the currently configured types.
      *
@@ -88,6 +103,8 @@ class TypeMap
      * $query->types(['created' => 'time']);
      * ```
      *
+     * This method will replace all the existing type maps with the ones provided.
+     *
      * @param array $types associative array where keys are field names and values
      * are the correspondent type.
      * @return $this|array

+ 1 - 1
src/ORM/Query.php

@@ -143,7 +143,7 @@ class Query extends DatabaseQuery implements JsonSerializable
         foreach ($schema->columns() as $f) {
             $fields[$f] = $fields[$alias . '.' . $f] = $schema->columnType($f);
         }
-        $this->defaultTypes($fields);
+        $this->typeMap()->addDefaults($fields);
 
         return $this;
     }