annotations
annotations copied to clipboard
Annotations from Traits are ignored
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.
/** @ODM\Document */
abstract class BaseDocument extends MappedSuperclass {
/** @ODM\Id */
public $id;
}
Then we set up concrete document like this:
/** @ODM\Document */
class UserDocument extends BaseDocument {
}
And we want have its id incremental instead of native Mongo id.
/** @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.
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.
The current version of doctrine/annotations is 1.6.0: please upgrade to that first.
Sorry, my bad, as I copied the text form the different package (doctrine/mongodb-odm), I copied the version of that package. I am on doctrine/annotations v 1.6.0.
Ping @Ocramius I cannot reassign to you.
I can confirm this issue with the latest doctrine/annotations version (1.13.0).
Our case is a @ORM\Column property defined in a base entity without assertions. An entity extending this one uses a trait where we add an @Assert\NotBlank annotation to the property. (The same is used in multiple extending entites, thus the trait).
Here we see that the NotBlank assertion is ignored. If we embed the property+annotation directly in the extending entity, the assertion works.