DDC-819: Attempting to search a recursive relationship by null results in an error... #1008

Open
opened 2026-01-22 12:58:43 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 26, 2010).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user omega:

I have an entity which has a many to one relationship pointing to itself. This is ultimately set to map parent/child relationships.

Consider the following snippet:

    // Start out assuming we are searching for "Pages" with no parent specified (root level).
    $parentId = null;

    // Check to see if we're fetching pages that are a child of a parent.
    if(array*key_exists("parent_id", $*GET)) {
        $parentId = $*GET['parent*id'];
    }

    $pages = $this->entityManager->getRepository("MyNamespace\Models\Page")->findByParent($parentId);

When this code is run, PHP tells me:

PHP Fatal error:  Uncaught exception 'Doctrine\\ORM\\ORMException' with message 'You need to pass a parameter to 'findByParent''

At which point, it's obvious that it's expecting a parameter an receiving none. The problem here however is that I have no way of matching for null. Is there some kind of surrogate null php-class that can be created to represent a model-null?

Originally created by @doctrinebot on GitHub (Sep 26, 2010). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user omega: I have an entity which has a many to one relationship pointing to itself. This is ultimately set to map parent/child relationships. Consider the following snippet: ``` // Start out assuming we are searching for "Pages" with no parent specified (root level). $parentId = null; // Check to see if we're fetching pages that are a child of a parent. if(array*key_exists("parent_id", $*GET)) { $parentId = $*GET['parent*id']; } $pages = $this->entityManager->getRepository("MyNamespace\Models\Page")->findByParent($parentId); ``` When this code is run, PHP tells me: ``` PHP Fatal error: Uncaught exception 'Doctrine\\ORM\\ORMException' with message 'You need to pass a parameter to 'findByParent'' ``` At which point, it's obvious that it's expecting a parameter an receiving none. The problem here however is that I have no way of matching for null. Is there some kind of surrogate null php-class that can be created to represent a model-null?
admin added the Bug label 2026-01-22 12:58:43 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#1008