doctrine / doctrine/annotations

Annotations from Traits are ignored

Open
#216 3 comments 3 reactions 1 assignee Claimed by @Ocramius View on GitHub
bug invalid
Dominant language
PHP
Stars
6.7k
Forks
234
PR merge metrics
No merged PRs in 30d

Description

I am copying this from https://github.com/doctrine/mongodb-odm/issues/1842 as requested by mr. @malarzm :

> All in all, this all boils down to annotation and reading them thus there's nothing we can do within
> ODM to change the behaviour. Could you please submit an issue to
> https://github.com/doctrine/annotations as that's where the work needs to be done?

### Bug Report

| Q | A
|------------ | ------
| BC Break | formally yes, but practically no :)
| Version | 1.6.0

#### Summary

We use traits to customize features for our Documents. It however looks like Doctrine ignores annotations from traits. Changing annotations for the class in trait doesn't have any effect.

#### Current behavior

ID's are native Mongo instead of autoincremental even if autoincrement is specified in the fields overloaded version in trait.

#### How to reproduce

Let's say we have our base document set up to have `id`.

```php
/** @ODM\Document */
abstract class BaseDocument extends MappedSuperclass {
/** @ODM\Id */
public $id;
}
```

Then we set up concrete document like this:

```php
/** @ODM\Document */
class UserDocument extends BaseDocument {
}
```

And we want have its id incremental instead of native Mongo id.

```php
/** @ODM\Document */
class UserDocument extends BaseDocument {
/** @ODM\Id(strategy="Increment") */
public $id;
}
```

But we want to do it with trait. Because this behaviour is repeated in other documents.

```php

trait TIncrementalID {
/** @ODM\Id(strategy="Increment") */
public $id;
}

/** @ODM\Document */
class UserDocument extends BaseDocument {
use TIncrementalID;
}
```

And this does not work and trait is ignored whatsoever. We also cannot implement abstract class because the autoincremental documents need to extend other classes. E.g. we have several classes of users, some of them need to be autoincremental some not.

#### Expected behavior

ID of class should be autoincremental when this is specified in trait.

Please, follow this https://github.com/doctrine/mongodb-odm/issues/1842 discussion with @malarzm that explains why I think this is a bug.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.