Skip to content
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

Account for inversedBy being a non-falsy-string or null #11275

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
): 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 @@
): 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 @@
): 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
Loading