Skip to content
\n

The Post and Comment entity is a one-to-many relation, and I set the relation on both side.

\n

But on the Comment, I added a [Ignore] to avoid serialization on post field.

\n
#[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;
\n

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;

\n

doesn't exist anymore in 8.0
\nbecause they are not Annotations, but Attributes:
\n

\n \n
\n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n\n \n \n \n \n
namespace Symfony\\Component\\Serializer\\Attribute;
/**
* @author Kévin Dunglas <[email protected]>
*/
#[\\Attribute(\\Attribute::TARGET_METHOD | \\Attribute::TARGET_PROPERTY)]
class Ignore
\n
\n
\n

\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"}}}
Discussion options

You must be logged in to vote

@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:

namespace Symfony\Component\Serializer\Attribute;
/**
* @author Kévin Dunglas <[email protected]>
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)]
class Ignore

in <= 7.4 there was a fallback from Annotation to Attributes that got removed with 8.0

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by hantsy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants