Doctrine Common
  1. Doctrine Common
  2. DCOM-224

If @ManyToOne targetEntity contains class name with double slashes, "Cannot redeclare class" error is raised

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: 2.4.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      If @ManyToOne (and apparently any other association annotation) contains targetEntity with "wrongly" defined fully qualified class name in format like My\\Entity
      Class, Fatal error "Cannot redeclare class" is raised when running command to generate schema.

      It would be more intuitive (and save some debugging hours if a proper exception of wrongly defined class name would be raised.

        Activity

        Hide
        Luis Cordova added a comment -

        i haven't tried annotations yet but in yml and on master this gives me:

        [Doctrine\ORM\Mapping\MappingException]
        The target-entity Acme\DemoBundle\Entity\UserX cannot be found in 'Acme\DemoBundle\Entity\Category#users
        '.

        let me try annotations ...

        Show
        Luis Cordova added a comment - i haven't tried annotations yet but in yml and on master this gives me: [Doctrine\ORM\Mapping\MappingException] The target-entity Acme\DemoBundle\Entity\UserX cannot be found in 'Acme\DemoBundle\Entity\Category#users '. let me try annotations ...
        Hide
        Luis Cordova added a comment -

        yeah this should be pretty much closed @ocramius @beberlei

        Show
        Luis Cordova added a comment - yeah this should be pretty much closed @ocramius @beberlei
        Show
        Luis Cordova added a comment - https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L945
        Hide
        Marco Pivetta added a comment -

        Copied comment from 2844:

        The issue should try to create a mapping of the kind

        @ManyToOne(targetEntity="Foo\\Bar")
        

        explicitly using two backslashes in the namespace seperator and try if an error occurs. This might be autoloader and Operating System dependent. Even if there is no error, we should fix "Doctrine\ORM\Mapping\ClassMetadataInfo" to replace double backslashes everywhere with one backslash correctly. This affects targetEntity and DiscrimnatorMap.

        Show
        Marco Pivetta added a comment - Copied comment from 2844: The issue should try to create a mapping of the kind @ManyToOne(targetEntity= "Foo\\Bar" ) explicitly using two backslashes in the namespace seperator and try if an error occurs. This might be autoloader and Operating System dependent. Even if there is no error, we should fix "Doctrine\ORM\Mapping\ClassMetadataInfo" to replace double backslashes everywhere with one backslash correctly. This affects targetEntity and DiscrimnatorMap.
        Hide
        Marco Pivetta added a comment -

        I'd rather throw an exception to warn the user about the abuse of backslashes.

        Show
        Marco Pivetta added a comment - I'd rather throw an exception to warn the user about the abuse of backslashes.
        Hide
        Marco Pivetta added a comment -

        Moved to doctrine common, since it's an issue with how metadata is being loaded when referenced

        Show
        Marco Pivetta added a comment - Moved to doctrine common, since it's an issue with how metadata is being loaded when referenced
        Hide
        Marco Pivetta added a comment -
        Show
        Marco Pivetta added a comment - Provided a hotfix at https://github.com/doctrine/common/pull/309

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Ville Mattila
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: