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

Cannot use a document against multiple classes

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Description

      It would be useful to be able to use two classes on one document, in a way that transparently extends the original schema. My use case:

      I have a base Application that manages users of the system. A module/plugin to the system wants to extend the User records to include references to one of it's documents:

      namespace Application\Model;
      class User {
      //user properties here
      }

      ...

      namespace Organisation\Model;
      use Application\Model\User as BaseUser;

      class Organisation {
      //organisations properties
      }

      class User extends BaseUser {
      /** @ReferenceOne(targetDocument="\Organisation\Model\Organisation") */
      protected $organisation
      }

      It this theoretical scenario, the original \Application\Model\User needs to be used by the base application, but the \Organisation\Model\User can be used by the addon module to transparently add more data to the same user. The base class doesn't need to know it will be used this way.

      Current behaviour for the above will ignore the additional properties not available in the parent class, and doesn't throw any exceptions/errors.

      Other ways to make it work involve the base class knowing it will be extended via SCI, or using a mappedsuperclass?, which isn't transparent in the base class, it needs to be altered to work with it's children.

        Activity

        Scott Aubrey created issue -
        Hide
        Jonathan H. Wage added a comment - - edited

        We have inheritance options that will allow that. Wouldn't this do the trick?

        namespace Application\Model;
        
        /** @MappedSuperclass(collection="users") */
        class BaseUser
        {
            // ...
        }
        
        /** @Document */
        class User extends BaseUser
        {
            // ...
        }
        
        namespace Organisation\Model;
        
        use Application\Model\BaseUser;
        
        /** @Document */
        class User extends BaseUser
        {
            // ...
        }
        
        Show
        Jonathan H. Wage added a comment - - edited We have inheritance options that will allow that. Wouldn't this do the trick? namespace Application\Model; /** @MappedSuperclass(collection= "users" ) */ class BaseUser { // ... } /** @Document */ class User extends BaseUser { // ... } namespace Organisation\Model; use Application\Model\BaseUser; /** @Document */ class User extends BaseUser { // ... }
        Jonathan H. Wage made changes -
        Field Original Value New Value
        Status Open [ 1 ] Closed [ 6 ]
        Resolution Invalid [ 6 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=MODM-31, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated:
              Resolved: