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

Problems with EmbedMany and discrimatorMap and discriminatorField

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.0.0ALPHA1
    • Fix Version/s: 1.0.0BETA1
    • Component/s: None
    • Labels:
      None

      Description

      I'm experiencing a problem when trying to embed documents and specify my own discriminatorMap and Field.

      This is the code I have:

          /** @Document(collection = "ticket") */
          class App_Model_Ticket extends App_Model_Abstract
          {
          	/**
          	 * @EmbedMany(
          	 *	discriminatorField = "type",
          	 *	discriminatorMap={
          	 *		"twitter"="App_Model_Ticket_Twitter",
      	 *		"email"="App_Model_Ticket_Email"
      	 *	})
      	 */
          	protected $messages = array();
          
          	// [...]
          }
      
      

      App_Model_Abstract is a MappedSuperClass.

      App_Model_Ticket_Email and App_Model_Ticket_Twitter pretty much look alike right now:

          /** @EmbeddedDocument */
          class App_Model_Ticket_Email extends App_Model_Ticket_Message
          {
          }
      

      and App_Model_Ticket_Message is another MappedSuperClass that extends App_Model_Abstract.

      Now, whenever I create a new model and persist it to mongoDB, the entry gets created and looks like this:

          [_id] => MongoId Object (
          )
          [messages] => Array (
              [0] => Array (
                  [message] => Lorem ipsum
                  [subject] => Ich bin ein Berliner22
                  [dateSent] => MongoDate Object (
                      [sec] => 1280909855
                      [usec] => 0
                  )
                  [_doctrine_class_name] => App_Model_Ticket_Twitter
              )
              [1] => Array (
                  [message] => Lorem ipsum
                  [subject] => Ich bin ein Berliner22
                  [dateSent] => MongoDate Object (
                      [sec] => 1280909855
                      [usec] => 0
                  )
                  [_doctrine_class_name] => App_Model_Ticket_Email
              )
          )
          [subject] => Ich bin ein Berliner22
          [dateCreated] => MongoDate Object (
              [sec] => 1280909855
              [usec] => 0
          )
          [dateLastMessage] => MongoDate Object (
              [sec] => 1280909855
      

      However, as you can see no type field for my embedded documents, it still uses _doctrine_class_name.

      But when I try to fetch this object, I get an exception saying "Class not found".

      I think this is because right now Doctrine ODM does not write into the custom discriminatorField with embedded documents, but reads from it.

        Activity

        Show
        Jonathan H. Wage added a comment - http://github.com/doctrine/mongodb-odm/commit/618896bb8d879a8365dc359a8949c9d2cad5bec7

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Sebastian Hoitz
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: