Skip to content

Handle document relation compatibility#23

Open
paulinevos wants to merge 2 commits intodoctrine:0.1.xfrom
paulinevos:validate-relations
Open

Handle document relation compatibility#23
paulinevos wants to merge 2 commits intodoctrine:0.1.xfrom
paulinevos:validate-relations

Conversation

@paulinevos
Copy link
Contributor

Helper test still failing because of metadata cache -- will try to fix that tomorrow.

@paulinevos paulinevos requested a review from GromNaN March 18, 2026 17:15
`Reference*` relationships cannot target `EmbeddedDocument`s and
vice-versa for standalone `Document`s. This commit adds checks for
compatibility and offers to change the document type (if possible).
When a document is generated with `make:document`, it now offers the
$metadata = $this->registry->getManager()->getClassMetadata($className);

if ($metadata === null) {
throw new RuntimeException($className . '" is not a valid document.');
Copy link
Member

Choose a reason for hiding this comment

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

Opening quote is missing.

Suggested change
throw new RuntimeException($className . '" is not a valid document.');
throw new RuntimeException(sprintf('"%s" is not a valid document.', $className));


use function sprintf;

final class IncompatibleParentRelationException extends Exception
Copy link
Member

Choose a reason for hiding this comment

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

I would disable this phpcs rule. Having an exception class that does not end with ...Exception is unconventional.

parent::__construct($message);
}

public static function forEmbeddingParents(string $className, string ...$parents): self
Copy link
Member

Choose a reason for hiding this comment

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

The factory methods should be @internal.

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