[MODM-31] Cannot use a document against multiple classes Created: 29/Jul/10  Updated: 30/Jul/10  Resolved: 30/Jul/10

Status: Closed
Project: Doctrine MongoDB ODM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major
Reporter: Scott Aubrey Assignee: Jonathan H. Wage
Resolution: Invalid Votes: 0
Labels: None
Environment:

Mac OS X 10.6.4, Built in PHP with extra modules:
zend_extension=xdebug.so
extension=mongo.so
extension=mssql.so
extension=xdiff.so
extension=pcntl.so
extension=imap.so
extension=mcrypt.so

Doctrine Commond/DBAL/ODM from git



 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.



 Comments   
Comment by Jonathan H. Wage [ 29/Jul/10 ]

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
{
    // ...
}
Generated at Tue Jul 29 06:48:18 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.