Skip to content

Commit

Permalink
Account for inversedBy being a non-falsy-string or null
Browse files Browse the repository at this point in the history
It is supposed to hold the name of a PHP property, and those cannot be
falsy strings.
  • Loading branch information
greg0ire committed Feb 20, 2024
1 parent 6290747 commit e0081b5
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function prepare(): void
}

// handle fetch-joined owning side bi-directional one-to-one associations
if ($assoc->inversedBy) {
if ($assoc->inversedBy !== null) {
$class = $this->getClassMetadata($className);
$inverseAssoc = $class->associationMappings[$assoc->inversedBy];

Expand Down Expand Up @@ -439,7 +439,7 @@ protected function hydrateRowData(array $row, array &$result): void
if ($relation->isOwningSide()) {
// TODO: Just check hints['fetched'] here?
// If there is an inverse mapping on the target class its bidirectional
if ($relation->inversedBy) {
if ($relation->inversedBy !== null) {
$inverseAssoc = $targetClass->associationMappings[$relation->inversedBy];
if ($inverseAssoc->isToOne()) {
$targetClass->reflFields[$inverseAssoc->fieldName]->setValue($element, $parentObject);
Expand Down
6 changes: 3 additions & 3 deletions src/Mapping/Builder/ClassMetadataBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ public function addManyToOne(
): ClassMetadataBuilder {
$builder = $this->createManyToOne($name, $targetEntity);

if ($inversedBy) {
if ($inversedBy !== null) {

Check warning on line 291 in src/Mapping/Builder/ClassMetadataBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Builder/ClassMetadataBuilder.php#L291

Added line #L291 was not covered by tests
$builder->inversedBy($inversedBy);
}

Expand Down Expand Up @@ -348,7 +348,7 @@ public function addOwningOneToOne(
): ClassMetadataBuilder {
$builder = $this->createOneToOne($name, $targetEntity);

if ($inversedBy) {
if ($inversedBy !== null) {

Check warning on line 351 in src/Mapping/Builder/ClassMetadataBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Builder/ClassMetadataBuilder.php#L351

Added line #L351 was not covered by tests
$builder->inversedBy($inversedBy);
}

Expand Down Expand Up @@ -380,7 +380,7 @@ public function addOwningManyToMany(
): ClassMetadataBuilder {
$builder = $this->createManyToMany($name, $targetEntity);

if ($inversedBy) {
if ($inversedBy !== null) {

Check warning on line 383 in src/Mapping/Builder/ClassMetadataBuilder.php

View check run for this annotation

Codecov / codecov/patch

src/Mapping/Builder/ClassMetadataBuilder.php#L383

Added line #L383 was not covered by tests
$builder->inversedBy($inversedBy);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public function loadOneToOneEntity(AssociationMapping $assoc, object $sourceEnti
$targetClass = $this->em->getClassMetadata($assoc->targetEntity);

if ($assoc->isOwningSide()) {
$isInverseSingleValued = $assoc->inversedBy && ! $targetClass->isCollectionValuedAssociation($assoc->inversedBy);
$isInverseSingleValued = $assoc->inversedBy !== null && ! $targetClass->isCollectionValuedAssociation($assoc->inversedBy);

// Mark inverse side as fetched in the hints, otherwise the UoW would
// try to load it in a separate query (remember: to-one inverse sides can not be lazy).
Expand Down
2 changes: 1 addition & 1 deletion src/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function validateClass(ClassMetadata $class): array
}
}

if ($assoc->isOwningSide() && $assoc->inversedBy) {
if ($assoc->isOwningSide() && $assoc->inversedBy !== null) {
if ($targetMetadata->hasField($assoc->inversedBy)) {
$ce[] = 'The association ' . $class->name . '#' . $fieldName . ' refers to the inverse side ' .
'field ' . $assoc->targetEntity . '#' . $assoc->inversedBy . ' which is not defined as association.';
Expand Down
2 changes: 1 addition & 1 deletion src/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,7 @@ public function createEntity(string $className, array $data, array &$hints = [])
$this->originalEntityData[$oid][$field] = $newValue;
$class->reflFields[$field]->setValue($entity, $newValue);

if ($assoc->inversedBy && $assoc->isOneToOne() && $newValue !== null) {
if ($assoc->inversedBy !== null && $assoc->isOneToOne() && $newValue !== null) {
$inverseAssoc = $targetClass->associationMappings[$assoc->inversedBy];
$targetClass->reflFields[$inverseAssoc->fieldName]->setValue($newValue, $entity);
}
Expand Down

0 comments on commit e0081b5

Please sign in to comment.