-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
getAssociationMappedByTargetField on the owning side of a relation fails in 3.0 #11250
Comments
cc @greg0ire |
To avoid the problem, downgrade doctrine/orm while waiting for a correction |
That's a violation of the contract in persistence. The ORM CM class should have a signature compatible with that of the persistence CM class. It is documented to always return a string: https://github.com/doctrine/persistence/blob/e7cf418cafe83a75f7a7096cc9fa890b201d28f1/src/Persistence/Mapping/ClassMetadata.php#L126-L131 I think we should replace the assertion with a |
In 2.x, getAssociationMappedByTargetField() used to return null when called with the owning side of an association. That was undocumented and wrong because the phpdoc advertises a string as a return type. In 6ce0cf4, I wrongly assumed that nobody would be calling this method with the owning side of an association. Let us throw a full fledged exception and advertise the proper way of avoiding this situation. Closes doctrine#11250
`getAssociationMappedByTargetField()` returns `null` when called with the owning side of an association. This is undocumented and wrong because the phpdoc advertises a string as a return type. Instead, callers should ensure they are calling that method with an inverse side. Closes doctrine#11250
`getAssociationMappedByTargetField()` returns `null` when called with the owning side of an association. This is undocumented and wrong because the phpdoc advertises a string as a return type. Instead, callers should ensure they are calling that method with an inverse side. Closes doctrine#11250
`getAssociationMappedByTargetField()` returns `null` when called with the owning side of an association. This is undocumented and wrong because the phpdoc advertises a string as a return type. Instead, callers should ensure they are calling that method with an inverse side. Closes doctrine#11250
|
The solution resolved the association error but still getting the following error php version: Error messageContext: Calling Doctrine\ORM\Mapping\ClassMetadata::getAssociationMappedByTargetField() with "ro
!! le", which is the owning side of an association.
!! Problem: The owning side of an association has no "mappedBy" field.
!! Solution: Call Doctrine\ORM\Mapping\ClassMetadata::isAssociationInverseSide() to check first in .
!! (which is being imported from "C:\zein_workspace\FAST\fast-api-v2\config/routes/api_platform.yam
!! l"). Make sure there is a loader supporting the "api_platform" type. Role class#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ApiResource]
class Role
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 64)]
private ?string $name = null;
#[ORM\OneToMany(targetEntity: User::class, mappedBy: 'role')]
private Collection $users;
public function __construct()
{
$this->users = new ArrayCollection();
}
/// etc
}
User Class#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ApiResource]
class User
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $firstName = null;
#[ORM\ManyToOne(targetEntity: Role::class, inversedBy: 'users')]
#[ORM\JoinColumn(nullable: false, name: "role_id", referencedColumnName: "id")]
private ?Role $role = null;
public function __construct()
{
}
// etc
} i am following the example provided by doctrine project documentation page hereis there anything i am missing? |
@ZeinMansor you need to address this inside API platform. If you can't, then report this to API platform. |
BC Break Report
Summary
Calling
Doctrine\ORM\Mapping\ClassMetadata::getAssociationMappedByTargetField
on a relation which is not an inverse side of a relation does not work anymore in 3.0Previous behavior
In 2.x, the method returned
null
for such cases.Current behavior
this assertion fails:
orm/src/Mapping/ClassMetadata.php
Line 2467 in 9acc70d
How to reproduce
I found this when investigating a support question in the Symfony Slack channel. This BC break affects ApiPlatform: https://github.com/api-platform/core/blob/8a35ee20c7aaf03b5a3d96baf920e2c99c5ae0fd/src/Doctrine/Orm/Metadata/Resource/DoctrineOrmLinkFactory.php#L70
To reproduce it, call
getAssociationMappedByTargetField
for a field being the owning side of a relation.The text was updated successfully, but these errors were encountered: