Skip to content

Commit

Permalink
Implemented fix for alias mapping bug, closes #237 and closes #145
Browse files Browse the repository at this point in the history
  • Loading branch information
FlipEverything committed Jan 17, 2018
1 parent c391426 commit 4e5536e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/Mapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1011,14 +1011,10 @@ public function convertToPHPValues($entityName, array $data)
{
$phpData = [];
$fields = $entityName::fields();
$fieldAliasMappings = $this->entityManager()->fieldAliasMappings();
$platform = $this->connection()->getDatabasePlatform();
$data = $this->resolver()->dataWithOutFieldAliasMappings($data);
$entityData = array_intersect_key($data, $fields);
foreach ($data as $field => $value) {
if ($fieldAlias = array_search($field, $fieldAliasMappings)) {
$field = $fieldAlias;
}

// Field is in the Entity definitions
if (isset($entityData[$field])) {
$typeHandler = Type::getType($fields[$field]['type']);
Expand Down
17 changes: 17 additions & 0 deletions lib/Query/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ public function dataWithFieldAliasMappings(array $data)
return $fieldMappings;
}

/**
* Taken given aliased field name/value inputs and map them to their non-aliased names
*/
public function dataWithOutFieldAliasMappings(array $data)
{
// have to call fields() otherwise fieldAliasMappings() would return null on the first entity
$this->mapper->entityManager()->fields();
$fieldAliasMappings = $this->mapper->entityManager()->fieldAliasMappings();
foreach ($fieldAliasMappings as $field => $aliasedField) {
if (array_key_exists($aliasedField, $data)) {
$data[$field] = $data[$aliasedField];
unset($data[$aliasedField]);
}
}
return $data;
}

/**
* Execute provided query and return result
*
Expand Down

0 comments on commit 4e5536e

Please sign in to comment.