sonata-project / sonata-doctrine-extensions

Doctrine2 behavioral extensions
https://github.com/sonata-project/sonata-doctrine-extensions
MIT License
268 stars 40 forks source link

Load mapping earlier #514

Closed core23 closed 1 month ago

core23 commented 1 month ago

Subject

I am targeting this branch, because this is a bugfix.

Changelog

### Changed
 - Load mapping earlier (priority 10)

There is a problem if you want to the the doctrine extensions together with gedmo sluggable, because both loadClassMetadata event listener will run at the default priority (0).


The problem can be reproduced when defining a mapping using sonata:

        $collector = DoctrineCollector::getInstance();

        $collector->addAssociation(
            'role_table',
            self::MAP_MANY_TO_ONE,
            OptionsBuilder::createManyToOne('topic', 'topic_table')
                ->cascade(['persist'])
                ->addJoin([
                    'name'                 => 'topic_id',
                    'referencedColumnName' => 'id',
                    'nullable'             => false,
                    'onDelete'             => 'CASCADE',
                ])
        );

and having a entity mapping:

namespace App\Entity;

class Role {

    #[Gedmo\Slug(fields: ['name'], updatable: false, separator: '_', unique_base: 'topic')]
    protected ?string $slug = null;

   // ...
}

You receive an error:

  Unable to find [topic] as mapped property in entity - App\Entity\Role
VincentLanglet commented 4 weeks ago

Released as 2.4.1