Associations - threat empty string as null and do not load related entity #5301

Closed
opened 2026-01-22 15:03:57 +01:00 by admin · 1 comment
Owner

Originally created by @majkel89 on GitHub (Oct 24, 2016).

Originally assigned to: @Ocramius on GitHub.

Is it possible to configure doctrine to use null, empty string and/or zero as actual null value so that related entity is not loaded and Doctrine\ORM\EntityNotFoundException is not thrown.

I have external database that i have no control over that uses empty strings to to mark null value.

class ParentEntity {
    /**
     * @var ChildEntity
     * @ORM\ManyToOne(targetEntity="ChildEntity", fetch="EAGER")
     * @ORM\JoinColumn(name="child_id")
     */
    private $child;
}

$parent = new ParentEntity;
$parent->getChild(); // Doctrine\ORM\EntityNotFoundException is thrown when child_id equals ''
Originally created by @majkel89 on GitHub (Oct 24, 2016). Originally assigned to: @Ocramius on GitHub. Is it possible to configure doctrine to use null, `empty string` and/or `zero` as actual `null value` so that related entity is not loaded and `Doctrine\ORM\EntityNotFoundException` is not thrown. I have external database that i have no control over that uses empty strings to to mark null value. ``` php class ParentEntity { /** * @var ChildEntity * @ORM\ManyToOne(targetEntity="ChildEntity", fetch="EAGER") * @ORM\JoinColumn(name="child_id") */ private $child; } $parent = new ParentEntity; $parent->getChild(); // Doctrine\ORM\EntityNotFoundException is thrown when child_id equals '' ```
admin added the Won't FixInvalid labels 2026-01-22 15:03:57 +01:00
admin closed this issue 2026-01-22 15:03:57 +01:00
Author
Owner

@Ocramius commented on GitHub (Oct 24, 2016):

Big explanation at https://stackoverflow.com/questions/15502408/doctrine-2-use-default-0-values-instead-of-null-for-relation

Closing here. NULL means NULL, other things are not NULL, and won't be supported, as we'd just be opening a can of worms about FK integrity support in different RDBMSs

@Ocramius commented on GitHub (Oct 24, 2016): Big explanation at https://stackoverflow.com/questions/15502408/doctrine-2-use-default-0-values-instead-of-null-for-relation Closing here. `NULL` means `NULL`, other things are not `NULL`, and won't be supported, as we'd just be opening a can of worms about FK integrity support in different RDBMSs
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5301