Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations from Traits are ignored #216

Open
josefsabl opened this issue Aug 6, 2018 · 3 comments
Open

Annotations from Traits are ignored #216

josefsabl opened this issue Aug 6, 2018 · 3 comments
Assignees

Comments

@josefsabl
Copy link

josefsabl commented Aug 6, 2018

I am copying this from doctrine/mongodb-odm#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 doctrine/mongodb-odm#1842 discussion with @malarzm that explains why I think this is a bug.

@Ocramius
Copy link
Member

Ocramius commented Aug 6, 2018

The current version of doctrine/annotations is 1.6.0: please upgrade to that first.

@josefsabl
Copy link
Author

josefsabl commented Aug 8, 2018

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.

@mbrodala
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants