Dany
Dany

Reputation: 23

Symfony: Update entity without related entity

I need to update entity (PostMeta) without related entity (Post). The + code looks like this:

$post = $postRepository->findOneBy(['id' => $postId]);

$postMeta = new PostMeta;
$postMeta->setPost($post);
$postMeta->setMetaKey('views');
$postMeta->setMetaValue($count + 1);
$postMeta->setUser(null);
$postMeta->setDate(new \DateTime());

$this->_em->persist($postMeta);
$this->_em->flush($postMeta);

How to persist PostMeta entity, but not update Post entity?

Upvotes: 0

Views: 212

Answers (2)

AiD
AiD

Reputation: 1007

Check in your Entity PostMeta, in $post attribute remove if is there any cascade={persist}

Upvotes: 1

popota
popota

Reputation: 1

you do not update POST you only set postMeta post attribute so you can do your update with postMeta and Post will not be in any case modify

Upvotes: 0

Related Questions