Doctrine MongoDB ODM
  1. Doctrine MongoDB ODM
  2. MODM-180

@DiscriminatorField("type") was not working for me

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Description

      According to the current documentation http://docs.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/reference/annotations-reference.html#discriminatorfield it is

       
      use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
      /**
       * @MongoDB\Document
       * @MongoDB\InheritanceType("SINGLE_COLLECTION")
       * @MongoDB\DiscriminatorField("type")
       */
      class SuperUser
      {
          // ...
      }
      

      and I got the following exception

       
      [MongoException] zero-length keys are not allowed, did you use $ with double quotes?
      

      which was hard to track down in the first place, as there is no useful stack trace showed. What was working for me was:

       
      use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
      /**
       * @MongoDB\Document
       * @MongoDB\InheritanceType("SINGLE_COLLECTION")
       * @MongoDB\DiscriminatorField(fieldName="type")
       */
      class SuperUser
      {
          // ...
      }
      

        Activity

        Hide
        Jeremy Mikola added a comment -

        This was actually changed in https://github.com/doctrine/mongodb-odm/commit/ebb7d5fe826f448fc4a53203c23bcc85e610b858. The documentation from that change is what is currently published, but the code is still sitting in the master branch since there's no 1.0.0-BETA10 tag yet.

        Your work-around is valid, and will continue to work with 1.0.0-BETA10, since I've left BC support for the old annotation style. My apologies for the inconvenience.

        Show
        Jeremy Mikola added a comment - This was actually changed in https://github.com/doctrine/mongodb-odm/commit/ebb7d5fe826f448fc4a53203c23bcc85e610b858 . The documentation from that change is what is currently published, but the code is still sitting in the master branch since there's no 1.0.0-BETA10 tag yet. Your work-around is valid, and will continue to work with 1.0.0-BETA10, since I've left BC support for the old annotation style. My apologies for the inconvenience.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Michael
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: