I can't seem to update an entity when making a PUT
request.
It works fine when I want to modify single elements belonging to the entity but not anymore as soon as I try to update an array or an object within it.
This works fine
{
"order_number": "TEST NAME"
}
As soon as an array is involved nothing seems to happen.
The quantities in the request are different from the one in the original entity.
{
"order_number": "TEST NAME",
"items": [
{
"id": 248,
"quantity": 0,
"quantity_shipped": 252
}
]
}
EDIT:
Foo and Items have a OneToMany relationship as shown in the code below.
class Foo implements FooInterface
{
/**
* One Foo has Many Items.
* @ORM\OneToMany(targetEntity="Item", mappedBy="foo", cascade={"persist","remove"})
* @JMSSerializer\Groups({"list_orders", "order_details"})
* @JMSSerializer\MaxDepth(1)
* @JMSSerializer\Expose
*/
private $items;
}
I also use a Form to validate the data in the request, and the Items are defined as a CollectionType as expected.
class FooType extends AbstractType implements FormTypeInterface
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('items',CollectionType::class, array(
'entry_type'=>ItemType::class,
'entry_options' =>array('label'=>false),
'allow_add' => true,
'by_reference' => false,
))
}
}
The same was done for the Items:
class SalesOrderLineItemType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('quantity',TextType::class,array(
'constraints' =>array(
new NotBlank())
)),
->add('quantityShipped',TextType::class,array(
'constraints' =>array(
new NotBlank())
))
->add('Foo',EntityType::class, array(
'class'=>'App:Api\Foo',
'constraints' =>array(
new Required(),
),
))
}
}
Does anyone know why this is happening?
Do I need to use a forEach loop to check each element?
I'm sure there's a more direct and efficient way of doing this.