This may ruin everything.
authorCameron Ball <cameron@getapproved.com.au>
Mon, 29 Dec 2014 09:03:12 +0000 (17:03 +0800)
committerCameron Ball <cameron@getapproved.com.au>
Mon, 29 Dec 2014 09:03:12 +0000 (17:03 +0800)
DataAccess/DataMapper/DataMapper.php
DataAccess/DataMapper/Helpers/AbstractPopulationHelper.php

index 3900522..a7bef4f 100644 (file)
@@ -56,7 +56,7 @@ class DataMapper implements IDataMapper
                 $class = $r->newInstanceArgs($constructors);\r
             }\r
 \r
-            $class->setId($row['id']);\r
+            $class->setId((int)$row['id']);\r
             $entities[$row['id']] = $class;\r
         }\r
                 \r
@@ -70,7 +70,7 @@ class DataMapper implements IDataMapper
             $queries = AbstractPopulationHelper::generateUpdateSaveQuery($this->_maps, $entity, $entity->getId(), $this->_db);\r
             $mergeMap = array();\r
             $flattened = array();\r
-\r
+            \r
             foreach($queries as $index => $query)\r
             {\r
                 $this_table = $query['table'];\r
@@ -155,7 +155,7 @@ class DataMapper implements IDataMapper
 \r
                 $queries[$index] = $query;\r
             }\r
-            \r
+\r
            // if($queries['TYPE'] == AbstractPopulationHelper::QUERY_TYPE_CREATE)\r
            // {\r
                 $idMap = [];\r
index 8e9ac84..fd14d52 100644 (file)
@@ -368,9 +368,21 @@ class AbstractPopulationHelper
     {\r
         $mapsIndex = self::getMapsNameFromEntityObject($VO, $maps);\r
         $table = $maps[$mapsIndex]['table'];\r
-        \r
-        $columns = array_merge(self::resolveColumnNamesAndValues($maps, $VO), $extraColumns);\r
-        \r
+\r
+        //TODO: This may break everythign, but I _think_ if I pass extraColuns, it is always an id column.\r
+        //I also think that this method is only called when we are trying to work out a VO (NOT a VOArray)\r
+        //in which case there should be one unique row somewhere in the database that corresponds to the VO\r
+        //we want, in that case we can just find it by id. Throwing in more columns causes issues trying to\r
+        //update an existing VO because it uses the values of the current object, which we are trying to save,\r
+        //so it never finds the existing row and therefore makes a whole new one, which ruins everything.\r
+        if($extraColumns)\r
+        {\r
+            $columns = $extraColumns;\r
+        } else {\r
+            //I only had this before, I think I don't actually need to do this merge but I'm leaving it incase\r
+            $columns = array_merge(self::resolveColumnNamesAndValues($maps, $VO), $extraColumns);\r
+        }\r
+\r
         $query = "SELECT * FROM $table where ";\r
         \r
         foreach($columns as $columnName => $columnValue)\r
@@ -380,6 +392,7 @@ class AbstractPopulationHelper
         }\r
         \r
         $query = substr($query, 0, -4);\r
+\r
         $statement = $db->prepare($query);\r
         $statement->execute();\r
         $row = $statement->fetch();\r