Skip to content

TreeObjectHydrator causes an exception "Unknown property "mappedBy" on class ManyToOneAssociationMapping" #2921

Open
@hotaru-ru

Description

Environment

Development Env

Package

show

$ composer show --latest gedmo/doctrine-extensions
# Put the result here.

name : gedmo/doctrine-extensions descrip. : Doctrine behavioral extensions keywords : Blameable, behaviors, doctrine, extensions, gedmo, loggable, nestedset, odm, orm, sluggable, sortable, timestampable, translatable, tree, uploadable versions : * v3.18.0 released : 2025-02-01, last week latest : v3.18.0 released 2025-02-01, last week type : library license : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText homepage : http://gediminasm.org/ source : [git] https://github.com/doctrine-extensions/DoctrineExtensions.git 964db6c dist : [zip] https://api.github.com/repos/doctrine-extensions/DoctrineExtensions/zipball/964db6c4fb5b0fc8aa25cc31b17471b4963460c6 964db6c path : D:\projects\Venera\venera-carpet.ru\src\Venera\vendor\gedmo\doctrine-extensions names : gedmo/doctrine-extensions

Doctrine packages

show

$ composer show --latest 'doctrine/*'
# Put the result here.
    "doctrine/doctrine-bundle": "^2.13",
    "doctrine/doctrine-migrations-bundle": "^3.4",
    "doctrine/orm": "^3.3",

PHP version

$ php -v
# Put the result here.

PHP 8.4.2 (cli) (built: Dec 17 2024 17:30:12) (ZTS Visual C++ 2022 x64) Copyright (c) The PHP Group Zend Engine v4.4.2, Copyright (c) Zend Technologies with Zend OPcache v8.4.2, Copyright (c), by Zend Technologies with Xdebug v3.4.1, Copyright (c) 2002-2025, by Derick Rethans

Subject

Minimal repository with the bug

Steps to reproduce

  1. Create Category with nested tree example
    from documentation https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/tree.md#building-trees-from-your-entities
  2. And try to get tree by Entites (not array)
  3. I got the error
    An exception has been thrown during the rendering of a template ("Unknown property "mappedBy" on class Doctrine\ORM\Mapping\ManyToOneAssociationMapping").
  4. Then debug on
    src/Venera/vendor/gedmo/doctrine-extensions/src/Tree/Hydrator/ORM/TreeObjectHydrator.php
    on Line 249
            // Make sure the association is mapped by the parent property
            if ($associationMapping['mappedBy'] !== $this->parentField) {
                continue;
            }

$associationMapping['mappedBy'] call the exception because Category->parent does not have mappedBy


I fixed it by changing Category entity. Firstly I put $children and after put $parent property.

Expected results

Actual results

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions