1

Doctrine ODM has annotation (collection) to specify which name should be used for collection. It defaults to class name but can be changed easily.

However I have mapped superclass which is extended by other classes. Inheritance type is single collection and this collection is named after the base abstract class. How can I change this name?

Let's say I have class Base, that gets extended. But I want the collection to be named Items. I obviously don't want to change annotations in all extending classes as it is quite redundant and prone to error.

Josef Sábl
  • 7,538
  • 9
  • 54
  • 66

1 Answers1

1

As stated in the documentation

A mapped superclass cannot be a document and is not queryable.

thus it can't be mapped to any collection. You need to have a class having @Document and @InheritanceType annotations specified from which further documents will extend (the class can be abstract). You can either put it in between your mapped superclass or just have it instead. Also thanks to having a @Document mapped class you'll be able to query it while having concrete classes back.

malarzm
  • 2,831
  • 2
  • 15
  • 25
  • Thanks. I missed the point of MappedSuperclass. I somehow always thought it is alias for abstract and every class that is abstract should be MappedSuperclass. Changing the mapped superclass to document (and keeping it abstract) solved my problem. – Josef Sábl Mar 03 '17 at 15:34