Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3925

Symfony4 / Doctrine2 / FOSRestBundle - Inserting / Updating entities

$
0
0

It's my first time here so I hope so don't be to hard on me.I'm trying to develop an API Rest on Symfony4 with FosRestBundle, Doctrine2 and JMSSerializer.

Here's my problem:

I have 3 entities organized such as:

  1. client which contains extras and a culture
  2. culture
  3. extra

My annotations and associations are fine. But now I want to insert a client in my database by simply persist and flush my client object. The JSON I send in my body request looks like something like this:

{  client_name: "something"  culture: {    culture_id: x  }  extras: [    {      extra_name: "name1"    },    {      extra_name: "name2"    }  ]}

Now what I'd like here is simple : creating a client and its extras but not its culture which I know the ID. But if I persist and flush my client entity, culture will be treated the same way. And of course I have other information in my culture entity that I don't want to update.

  • Am I missing an annotation to avoid this and just take the ID culture without its content? Is there an annotation that I don't know of and that could solve this?
  • Should I get the culture from the database and set it to the client first (I'd like to avoid this to save some automatisms I set up)?

Hope you'll have some ideas guys!


Viewing all articles
Browse latest Browse all 3925

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>