Partage
  • Partager sur Facebook
  • Partager sur Twitter

Synfony 5.4 et ai_platform overwrites data

Sujet résolu
    16 septembre 2024 à 16:58:45

    Hello,

    I have a problem with api_platform which overwrites my relationship data if I don't provide it in my json.

    I am using symfony 5.4 old annotation


    For example in my class agent:

    /**
         * @var integer
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         * @Groups({"cons"})
         */
        private $id;
    
        /**
         * @var string
         * @Groups({"cons", "putAgent"})
         *
         * @ORM\Column(name="civilite", type="string", length=15, nullable=true)
         */
        private $civilite;
    
        /**
         * @var string
         * @Groups({"cons", "putAgent"})
         *
         * @ORM\Column(name="nom", type="string", length=50, nullable=true)
         */
        private $nom;
    
        /**
         * @var string
         * @ORM\Column(name="nomUsuel", type="string", length=50, nullable=true)
         * @Groups({"cons", "put"})
         */
        private $nomUsuel;
    
        /**
         * @Groups({"cons", "putAgent"})
         * @ORM\OneToOne(targetEntity="App\Entity\Coordonnees", cascade={"persist", "remove"})
         */
        private $coordonnees;

    and my class Coordonnees

    /**
         * @var integer
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;
    
        /**
         * @var string
         * @Groups({"putAgent", "cons"})
         *
         * @ORM\Column(name="numAdresse", type="string", length=10, nullable=true)
         */
        private $numAdresse;
    
        /**
         * @var string
         * @Groups({"putAgent", "cons"})
         *
         * @ORM\Column(name="nomAdresse", type="string", length=100, nullable=true)
         */
        private $nomAdresse;



    And my json :

    {
      "nom" : "JOE",
      "nomUsuel: "MACO",
      "coordonnees": {
        "nomAdresse" : "rue jean pasteur"
      }
    }

    If I have data in numAdresse, my data is overwritten by a null.

    Do you have any idea of the cause? I'm sure it must be stupid

    EDIT :

    In the end it was all stupid, I had to use the patch instead of the put. If this helps anyone...

    -
    Edité par YannYann35 17 septembre 2024 à 10:23:12

    • Partager sur Facebook
    • Partager sur Twitter

    Synfony 5.4 et ai_platform overwrites data

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    • Editeur
    • Markdown