Closed nilportugues closed 8 years ago
Use serializer to convert object to dot notation
With the usage of nilportugues/serializer problem is EASILY solved.
The method "toArray" for the Mapping lacks of any sense having this, which is not bad as it would simply the mapping.
<?php
/**
* @param QueryBuilder $query
* @param Identity $value
* @param bool $isInsert
*/
protected function populateQuery(QueryBuilder $query, Identity $value, $isInsert)
{
$mappings = $this->mapping->map();
if (!$isInsert) {
$mappings = $this->mappingWithoutIdentityColumn();
}
$serializer = new DeepCopySerializer(new FlatArrayTransformer()); //this should become a singleton
$object = $serializer->serialize($value); //this would require an inmemory registry
$setOperation = ($isInsert) ? 'setValue' : 'set';
foreach ($mappings as $objectProperty => $sqlColumn) {
$this->mappingGuard($objectProperty, $object, $value);
$placeholder = ':'.$sqlColumn;
$query->$setOperation($sqlColumn, $placeholder);
$query->setParameter($placeholder, $object[$objectProperty]); //this has been changed too.
}
}
This means modifying all the methods using
map()
... or wrap them into a new function instead.Test example:
Being the original class: