mongodbsymfonyormfosuserbundlesonata-user-bundle

FOSUserBundle use MongoDB config validation instead of ORM


I got a Symfony2 project with FOSUserBundle and SonataUserBundle. Both bundles are configured to use ORM only.

# FOS User Bundle
fos_user:
    db_driver: orm
    firewall_name: main
    user_class: MyBundle\Entity\User
    group:
        group_class: MyBundle\Entity\Group
    from_email:
        address: foo@bar.com
        sender_name: Foo Bar

# SONATA User Bundle
sonata_user:
    security_acl: false
    manager_type: orm
    class:
        user: MyBundle\Entity\User
        group: MyBundle\Entity\Group
    impersonating:
        route: homepage
    admin:
        user:
            class: MyBundle\Admin\UserAdmin
            controller: SonataAdminBundle:CRUD
            translation: SonataUserBundle

But when I want to use my User class, an error is thrown, telling MongoDB annotations classes cannot be found.

Attempted to load class "Unique" from namespace "\Symfony\Component\Validator\Constraints\Doctrine\Bundle\MongoDBBundle\Validator\Constraints". Did you forget a "use" statement for another namespace?

This message seems to be thrown by

/friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/mongodb.xml

As I didn't want to use MongoDB drivers, why is FOSUser using MongoDB validator ?


Solution

  • this seems to be a bug in the FOSUserBudle.

    As a dirty workaround, I copied the lines <constraint name="Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity"> from the orm.xml to mongodb.xml and couchdb.xml (all in /friendsofsymfony/user-bundle/FOS/UserBundle/Resources/config/validation/).

    Obviously, those files are in fact loaded, but should not.

    Edit: In fact this was a bug in FOSUserBundle and was fixed in version 1.3.6, see https://github.com/FriendsOfSymfony/FOSUserBundle/issues/1851#issuecomment-108411883