-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Nullable embedded objects. #1275
Changes from 4 commits
74d50f7
4ec25c8
93300bc
9cc7529
40dfa3f
6340eec
f48d05e
609d492
71d3580
6e57134
d27c5b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3213,6 +3213,7 @@ public function mapEmbedded(array $mapping) | |
$this->embeddedClasses[$mapping['fieldName']] = array( | ||
'class' => $this->fullyQualifiedClassName($mapping['class']), | ||
'columnPrefix' => $mapping['columnPrefix'], | ||
'nullable' => isset($mapping['nullable']) ? $mapping['nullable'] : null, | ||
'declaredField' => isset($mapping['declaredField']) ? $mapping['declaredField'] : null, | ||
'originalField' => isset($mapping['originalField']) ? $mapping['originalField'] : null, | ||
); | ||
|
@@ -3223,8 +3224,9 @@ public function mapEmbedded(array $mapping) | |
* | ||
* @param string $property | ||
* @param ClassMetadataInfo $embeddable | ||
* @param boolean $nullable | ||
*/ | ||
public function inlineEmbeddable($property, ClassMetadataInfo $embeddable) | ||
public function inlineEmbeddable($property, ClassMetadataInfo $embeddable, $nullable) | ||
{ | ||
foreach ($embeddable->fieldMappings as $fieldMapping) { | ||
$fieldMapping['originalClass'] = isset($fieldMapping['originalClass']) | ||
|
@@ -3238,6 +3240,10 @@ public function inlineEmbeddable($property, ClassMetadataInfo $embeddable) | |
: $fieldMapping['fieldName']; | ||
$fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName']; | ||
|
||
if ($nullable !== null) { | ||
$fieldMapping['nullable'] = $nullable; | ||
} | ||
|
||
if (! empty($this->embeddedClasses[$property]['columnPrefix'])) { | ||
$fieldMapping['columnName'] = $this->embeddedClasses[$property]['columnPrefix'] . $fieldMapping['columnName']; | ||
} elseif ($this->embeddedClasses[$property]['columnPrefix'] !== false) { | ||
|
@@ -3310,4 +3316,29 @@ public function getSequencePrefix(AbstractPlatform $platform) | |
|
||
return $sequencePrefix; | ||
} | ||
|
||
public function applyData($entity, array $data) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method naming is a bit weird: can you document it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll rename it. It is really weird. |
||
{ | ||
foreach ($data as $field => $value) { | ||
if ($this->shouldUseData($field, $value)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to cache this method call? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be done, but do you think is needed? I mean, the operations aren't too complex and they're based on attributes that are already caching the information (and only will rely on that attributes when the |
||
$this->reflFields[$field]->setValue($entity, $value); | ||
} | ||
} | ||
} | ||
|
||
private function shouldUseData($field, $value) | ||
{ | ||
if ( ! isset($this->fieldMappings[$field])) { | ||
return false; | ||
} | ||
|
||
if ($value !== null) { | ||
return true; | ||
} | ||
|
||
return isset( | ||
$this->fieldMappings[$field]['declaredField'], | ||
$this->embeddedClasses[$name = $this->fieldMappings[$field]['declaredField']] | ||
) && $this->embeddedClasses[$name]['nullable'] !== true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that extra parameters really required? Can't you use
$this->embeddedClasses[$property]['nullable']
in this method instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, my mistake.