Skip to content

Remove COLLECTION_PER_CLASS inheritance type - #3022

Open
GromNaN wants to merge 6 commits into
doctrine:3.0.xfrom
GromNaN:merge-2.17.x-into-3.0.x-4723
Open

Remove COLLECTION_PER_CLASS inheritance type#3022
GromNaN wants to merge 6 commits into
doctrine:3.0.xfrom
GromNaN:merge-2.17.x-into-3.0.x-4723

Conversation

@GromNaN

@GromNaN GromNaN commented Jun 29, 2026

Copy link
Copy Markdown
Member
Q A
Type improvement
BC Break yes
Fixed issues Fixes #2742. Deprecation introduced in #3011

Summary

Removes the COLLECTION_PER_CLASS inheritance type, deprecated in 2.17. Each document class is already mapped to its own collection, so the type provided no additional behavior. The mapping drivers now throw a MappingException when an unknown inheritance type is configured.

This PR also merges 2.17.x into 3.0.x.

GromNaN added 5 commits June 25, 2026 04:55
…on (doctrine#3021)

Ensures that a ReferenceMany PersistentCollection marked as dirty (same
instance, new element added) is detected as changed by computeChangeSets().
Unlike EmbedMany, ReferenceMany collections are excluded from the
association changeset loop, so detection relies solely on the dirty flag
check in computeOrRecomputeChangeSet().
* Deprecate COLLECTION_PER_CLASS inheritance type

This inheritance type persists one collection per class, which is already
the default behavior for any document. It provides no extra behavior and
cannot guarantee _id uniqueness across the distinct collections of a
hierarchy. Deprecate it with no replacement: remove the InheritanceType
mapping, each class remains mapped to its own collection.

Closes doctrine#2742

* Add trigger_deprecation to isInheritanceTypeCollectionPerClass()

Also refactor ClassMetadataFactory to compare against the constant
directly, avoiding an internal call to the now-deprecated method.
…-3.0.x-4723

# Conflicts:
#	src/Mapping/ClassMetadataFactory.php
The COLLECTION_PER_CLASS inheritance type, deprecated in 2.17, is removed
with no replacement. Each document class is already mapped to its own
collection, so the type provided no additional behavior.

The mapping drivers now throw a MappingException when an unknown
inheritance type is configured, instead of relying on an undefined
constant.
@GromNaN
GromNaN force-pushed the merge-2.17.x-into-3.0.x-4723 branch from d3a3e43 to 4f415b3 Compare June 30, 2026 06:58
@GromNaN GromNaN changed the title Merge 2.17.x into 3.0.x Remove COLLECTION_PER_CLASS inheritance type Jun 30, 2026
@GromNaN
GromNaN requested review from IonBazan and malarzm June 30, 2026 07:01

.. _collection_per_class_inheritance:

Collection Per Class Inheritance

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be good to keep a section and showing you can just extend documents and change the collection

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. There was already a section on MappedSuperclass, but I've revised the doc to make it clear that PHP inheritance just works.

@GromNaN
GromNaN force-pushed the merge-2.17.x-into-3.0.x-4723 branch from 2ef4082 to e6bf183 Compare June 30, 2026 08:48
@GromNaN
GromNaN force-pushed the merge-2.17.x-into-3.0.x-4723 branch from e6bf183 to 7d3fc4e Compare June 30, 2026 09:54
Comment on lines +176 to +181
$constantName = ClassMetadata::class . '::INHERITANCE_TYPE_' . $inheritanceType;
if (! defined($constantName)) {
throw MappingException::invalidInheritanceType($className, $inheritanceType);
}

$metadata->setInheritanceType(constant($constantName));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a follow-up PR, we can add support for using the const value in the InheritanceType attribute.

@GromNaN
GromNaN requested review from malarzm and paulinevos July 2, 2026 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants