I'm struggling with this strange behavior with my API: some of the attributes are set to readOnly: true
.
EDIT: This is how my entities are defined
/**
* @ApiResource(
* normalizationContext={"groups"={"read_partenaire"}},
* denormalizationContext={"groups"={"write_partenaire"}}
* )
* @ORM\Entity(repositoryClass="App\Repository\ProfessionnelRepository")
* @ApiFilter(SearchFilter::class, properties={"nom": "partial", "id": "exact"})
*/
class Professionnel
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"read_partenaire"})
*/
private $id;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Partenaire", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Groups({"read_partenaire","write_partenaire"})
*
*/
private $partenaire;
/**
* @ORM\Column(type="string", length=4)
* @Groups({"read_partenaire","write_partenaire"})
*
*/
private $civilite;
/**
* @ORM\Column(type="string", length=100)
* @Groups({"read_partenaire","write_partenaire"})
*
*/
private $nom;
/**
* @ORM\Column(type="string", length=100)
* @Groups({"read_partenaire","write_partenaire"})
*
*/
private $prenom;
The second entity :
/**
* @ApiResource(
* normalizationContext={"groups"={"read_partenaire"}},
* denormalizationContext={"groups"={"write_partenaire"}}
* )
* @ApiFilter(SearchFilter::class, properties={"id": "exact"})
* @ORM\Entity(repositoryClass="App\Repository\PartenaireRepository")
*/
class Partenaire
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"read_partenaire"})
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Ban", inversedBy="partenaires", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
* @Groups({"read_partenaire","write_partenaire"})
*/
private $ban;
The third entity:
/**
* @ApiResource()
* @ORM\Entity(repositoryClass="App\Repository\BanRepository")
*/
class Ban
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
* @Groups({"read_partenaire"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"read_partenaire","write_partenaire"})
*
*/
private $nom_voie;
To sum it up, my Professionnel
entity is nested to Partenaire
which is nested to Ban
. So by creating a new Professionnel
a new Partenaire
and Ban
should be created as well.
Please keep in mind that all the properties of my 3 entities have get
and set
functions (except id's of course)...but for some reason, the property nom_voie
of my third entity is set to readOnly (and because of that, the insert of all the entities fail...)
I'm not sure how exactly this two-level nesting should be expressed using Groups
I tried many combinations but no luck...