Skip to content

Support for referencing entities without foreign keys #802

Description

@PetrAda

Describe the bug
I can write * @property ?File $image {m:1 File, oneSided=true}
but if the backing ID is an invalid value eg 22. and a record with the id 22 does not exist the HasOne object throws an exception even though the property is nullable.

Expected behavior
NOT

abstract class HasOne implements IRelationshipContainer{
...
if (!$this->metadata->isNullable && !$allowNull) {
				throw new NullValueException($this->metadata);
			}
			return null;

		} elseif (is_scalar($entity)) {
			return $this->getTargetRepository()->getByIdChecked($entity);

		} 
...
}

YES

abstract class HasOne implements IRelationshipContainer{
...
if (!$this->metadata->isNullable && !$allowNull) {
				throw new NullValueException($this->metadata);
			}
			return null;

		} elseif (is_scalar($entity)) {
$repo = $this->getTargetRepository();
if ($this->metadata->isNullable || $allowNull) {
				return $repo->getById($entity)
			}
			return $repo->getByIdChecked($entity);

		} 
...
}

Versions::

  • Database: [PERCONA]
  • Orm: 3.0
  • Dbal: Dbal 3.0

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions