Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-898

Make DiscriminatorMap optional in Inheritance Mapping

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      It would be nice if a DiscriminatorMap was optional when defining Inheritance Mapping. For example, in dynamic environments where the actual classes that will extend a base class are not known, it would be much easier to have a default discriminator map created by Doctrine, which just mapped the class name to itself.

      Having the DiscriminatorMap is great for some uses, but I think it should just use the classnames by default. That would mean less work for the developer and a more flexible/simpler system overall.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        This is technically not possible (and wanted).

        Explaination is simple:

        Say i wouldnt define the Inheritance Mapping upfront and now do a query:

        SELECT u FROM Root u
        

        Since this query would hydrate ALL children of Root also. How would the code know which classes are parents? You cannot call find this out with Reflection or any other classes since you don't know for sure if the classes have been loaded using require_once yet.

        Show
        Benjamin Eberlei added a comment - This is technically not possible (and wanted). Explaination is simple: Say i wouldnt define the Inheritance Mapping upfront and now do a query: SELECT u FROM Root u Since this query would hydrate ALL children of Root also. How would the code know which classes are parents? You cannot call find this out with Reflection or any other classes since you don't know for sure if the classes have been loaded using require_once yet.
        Hide
        Alexander Trauzzi added a comment - - edited

        I brought up exactly the same issue in DDC-764 a while back.

        I don't understand the difficulty in allowing us to define a column in the superclass that Doctrine2 will use to to know what class name to use. Upon hydration, doctrine - in exactly the same way as with a discriminator map - will know which classes to instantiate. Class loading behaviour is basically identical.

        This is proven by the fact that almost every single discriminator map I've seen to date looks like this:

        "class_name" = "Class_Name"
        "another_class" = "Another_Class"

        Given this, I still maintain that discriminator maps are totally redundant and would love to hear more people sound off on this issue. This is a great dynamic feature with lots of merit. I think it deserves more research.

        Show
        Alexander Trauzzi added a comment - - edited I brought up exactly the same issue in DDC-764 a while back. I don't understand the difficulty in allowing us to define a column in the superclass that Doctrine2 will use to to know what class name to use. Upon hydration, doctrine - in exactly the same way as with a discriminator map - will know which classes to instantiate. Class loading behaviour is basically identical. This is proven by the fact that almost every single discriminator map I've seen to date looks like this: "class_name" = "Class_Name" "another_class" = "Another_Class" Given this, I still maintain that discriminator maps are totally redundant and would love to hear more people sound off on this issue. This is a great dynamic feature with lots of merit. I think it deserves more research.
        Hide
        Joshua Johnson added a comment -

        DDC-1542 duplicates this issue, and was fixed in Doctrine 2.3.

        Show
        Joshua Johnson added a comment - DDC-1542 duplicates this issue, and was fixed in Doctrine 2.3.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Nick Daugherty
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: