The Post and Comment entity is a one-to-many relation, and I set the relation on both side.
But on the Comment, I added a [Ignore] to avoid serialization on post field.
#[Entity(repositoryClass: CommentRepository::class)]\nclass Comment\n{\n // ...\n\n #[ManyToOne(targetEntity: \"Post\", inversedBy: \"comments\")]\n #[JoinColumn(name: \"post_id\", referencedColumnName: \"id\")]\n #[Ignore]\n private Post $post;The codes worked since Symfony v5.x - 7.3, but failed when upgrading v8.0.
","upvoteCount":1,"answerCount":2,"acceptedAnswer":{"@type":"Answer","text":"@hantsy
\nhttps://github.com/hantsy/symfony-rest-sample/blob/15843a0c5b7a93b3d00a903045a434cd775ed636/src/Entity/Comment.php#L17
\nuse Symfony\\Component\\Serializer\\Annotation\\Ignore;
doesn't exist anymore in 8.0
\nbecause they are not Annotations, but Attributes:
\n
\n symfony/src/Symfony/Component/Serializer/Attribute/Ignore.php\n
\n\n Lines 12 to 18\n in\n 32f6f6c\n
\n| \n | namespace Symfony\\Component\\Serializer\\Attribute; | \n
| \n | \n |
| \n | /** | \n
| \n | * @author Kévin Dunglas <[email protected]> | \n
| \n | */ | \n
| \n | #[\\Attribute(\\Attribute::TARGET_METHOD | \\Attribute::TARGET_PROPERTY)] | \n
| \n | class Ignore | \n
in <= 7.4 there was a fallback from Annotation to Attributes that got removed with 8.0
","upvoteCount":3,"url":"https://github.com/symfony/symfony/discussions/62542#discussioncomment-15103534"}}}-
|
I have tried to upgrade my Symfony example project https://github.com/hantsy/symfony-rest-sample to v8.0, there is a test failed due to error like this. https://github.com/hantsy/symfony-rest-sample/actions/runs/19756748559/job/56609665804#step:11:29 {"error":"A circular reference has been detected when serializing the object of
class \u0022App\\Entity\\Comment\u0022 (configured limit: 1)."}The But on the #[Entity(repositoryClass: CommentRepository::class)]
class Comment
{
// ...
#[ManyToOne(targetEntity: "Post", inversedBy: "comments")]
#[JoinColumn(name: "post_id", referencedColumnName: "id")]
#[Ignore]
private Post $post;The codes worked since Symfony v5.x - 7.3, but failed when upgrading v8.0. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
@hantsy doesn't exist anymore in 8.0 symfony/src/Symfony/Component/Serializer/Attribute/Ignore.php Lines 12 to 18 in 32f6f6c in <= 7.4 there was a fallback from Annotation to Attributes that got removed with 8.0 |
Beta Was this translation helpful? Give feedback.
@hantsy
https://github.com/hantsy/symfony-rest-sample/blob/15843a0c5b7a93b3d00a903045a434cd775ed636/src/Entity/Comment.php#L17
use Symfony\Component\Serializer\Annotation\Ignore;doesn't exist anymore in 8.0
because they are not Annotations, but Attributes:
symfony/src/Symfony/Component/Serializer/Attribute/Ignore.php
Lines 12 to 18 in 32f6f6c
in <= 7.4 there was a fallback from Annotation to Attributes that got removed with 8.0