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

Need a way to find all documents from collection by their base class

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Document Manager
    • Labels:
      None

      Description

      Imagine a use case:

      I have a set of classes, which extend abstract class BaseGridFsFile. All children classess are stored in same GridFs collection (using single collection inheritance).

      But I cannot fetch all files from this collection, regardless their type. I know that I can use array of subclasses to fetch, but this won't work in my case, because there is no static DiscriminatorMap.

      It whould be great if I could use something like this:

      $files = $dm->find('BaseGridFsFile', $query);
      

      and Doctrine would instantiate proper classes for found documents.

      Is it possible?

        Activity

        Hide
        Jonathan H. Wage added a comment -

        It is possible if you have a none abstract parent class that all other subclasses extend from. If you query that class the queries will include a $in query limiting the results to itself and all subclasses using the discriminator values.

        Show
        Jonathan H. Wage added a comment - It is possible if you have a none abstract parent class that all other subclasses extend from. If you query that class the queries will include a $in query limiting the results to itself and all subclasses using the discriminator values.
        Hide
        Jonathan H. Wage added a comment -

        Actually it should work even if it is abstract. It just must be a mapped document that has a discriminatorMap specified.

        Show
        Jonathan H. Wage added a comment - Actually it should work even if it is abstract. It just must be a mapped document that has a discriminatorMap specified.
        Hide
        Jonathan H. Wage added a comment -

        This should work. You can ask usage questions on the mailing list and open an issue for bugs or enhancements.

        Show
        Jonathan H. Wage added a comment - This should work. You can ask usage questions on the mailing list and open an issue for bugs or enhancements.
        Hide
        Vladimir Razuvaev added a comment -

        Yes, I checked. it works for non-abstract classes, with condition that queried class is in DiscriminatorMap for given collection.

        But it forces me to rework classes hierarchy to be able to use this feature. I think it would be great to have it work with abstract classes in future versions of ODM.

        Show
        Vladimir Razuvaev added a comment - Yes, I checked. it works for non-abstract classes, with condition that queried class is in DiscriminatorMap for given collection. But it forces me to rework classes hierarchy to be able to use this feature. I think it would be great to have it work with abstract classes in future versions of ODM.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Vladimir Razuvaev
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: