doctrine / mongodb-odm

The Official PHP MongoDB ORM/ODM
https://www.doctrine-project.org/projects/doctrine-mongodb-odm/en/latest/
MIT License
1.09k stars 502 forks source link

Mismatch between `ClassMetadata::getAssociationTargetClass` and its parent #2325

Closed franmomu closed 3 years ago

franmomu commented 3 years ago

Bug Report

Q A
BC Break no
Version 2.2.1

Summary

Currently, ClassMetadata::getAssociationTargetClass has ?string as return type:

https://github.com/doctrine/mongodb-odm/blob/ccf26d9e023387e9aae86951186c043b3222fe70/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L1794-L1804

but the interface ClassMetadata from doctrine/persistence uses string as return type (in the docblock).

I guess in doctrine/persistence 3.0, the interface will have return types and this would fail.

A deprecation could be triggered if the value is null, the only place I've seen this method is used, is in:

https://github.com/doctrine/mongodb-odm/blob/ccf26d9e023387e9aae86951186c043b3222fe70/lib/Doctrine/ODM/MongoDB/Query/Expr.php#L1415-L1421

I guess that $classMetadata->hasAssociation($key) could also be true for a field with discriminatorMap defined, so maybe we could add another check (I don't know which one).

malarzm commented 3 years ago

The problem is that in ODM you can have a reference without targetDocument and even without discriminatorMap - the ODM will happily store references to anything you feed it with. I have no idea what to do with this yet tho :)

malarzm commented 3 years ago

@franmomu the related issue was merged, do you need a release for doctrine/persistence to move this issue forward?

franmomu commented 3 years ago

there is no need for a release @malarzm, thank you for taking care of the issue!