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