Skip to content

Denormalizing bidirectional ManyToOne relations don't remove items #153

Description

@Drachenkaetzchen

I have configured a bidirectional ManyToOne/OneToMany relation:

Owning side:
https://github.com/partkeepr/PartKeepr/blob/sf2migration/src/PartKeepr/ManufacturerBundle/Entity/Manufacturer.php#L82
Inversing side: https://github.com/partkeepr/PartKeepr/blob/sf2migration/src/PartKeepr/ManufacturerBundle/Entity/ManufacturerICLogo.php#L14

When I attempt to remove items, I get the proper response from DunglasApiBundle where the removed items don't exist anymore, however, the items still persist in the database. Most likely DunglasApiBundle doesn't call EntityMananger->remove for removed entities, although I'm not sure if Doctrine can be configured to take care of that automatically.

Note that this only seems to happen for bidirectional ManyToOne/OneToMany relations.

Here's the example request:

{
   "icLogos":[
      {
         "@id":"/~felicitus/PartKeepr/web/app_dev.php/api/manufacturer_i_c_logo/2/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"8a2a5eb9-908b-4bd7-aec3-be18dbecb298",
         "originalFilename":"actel.png",
         "mimetype":"image/png",
         "size":5003,
         "extension":"png"
      },
      {
         "@id":"/~felicitus/PartKeepr/web/app_dev.php/api/manufacturer_i_c_logo/378/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"c85ccde8-236f-11e5-be7f-f8b156bec77a",
         "originalFilename":"test.png",
         "mimetype":"image/jpeg",
         "size":114281,
         "extension":"png"
      },
      {
         "@id":"/~felicitus/PartKeepr/web/app_dev.php/api/manufacturer_i_c_logo/379/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"262d1aa4-2370-11e5-9f54-f8b156bec77a",
         "originalFilename":"kappe.png",
         "mimetype":"image/png",
         "size":37141,
         "extension":"png"
      }
   ]
}

Response:

{
   "@context":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/contexts\/Manufacturer",
   "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturers\/2",
   "@type":"Manufacturer",
   "name":"ACTEL2",
   "address":null,
   "url":"foo\/bar",
   "email":null,
   "comment":null,
   "phone":null,
   "fax":null,
   "icLogos":[
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/2\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"8a2a5eb9-908b-4bd7-aec3-be18dbecb298",
         "originalFilename":"actel.png",
         "mimetype":"image\/png",
         "size":5003,
         "extension":"png"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/378\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"c85ccde8-236f-11e5-be7f-f8b156bec77a",
         "originalFilename":"test.png",
         "mimetype":"image\/jpeg",
         "size":114281,
         "extension":"png"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/379\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"262d1aa4-2370-11e5-9f54-f8b156bec77a",
         "originalFilename":"kappe.png",
         "mimetype":"image\/png",
         "size":37141,
         "extension":"png"
      }
   ]
}

So the returned JSON is fine, but removals aren't stored in the database. Here's a GET on the same resource without any changes:

{
   "@context":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/contexts\/Manufacturer",
   "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturers\/2",
   "@type":"Manufacturer",
   "name":"ACTEL2",
   "address":null,
   "url":"foo\/bar",
   "email":null,
   "comment":null,
   "phone":null,
   "fax":null,
   "icLogos":[
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/2\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"8a2a5eb9-908b-4bd7-aec3-be18dbecb298",
         "originalFilename":"actel.png",
         "mimetype":"image\/png",
         "size":5003,
         "extension":"png"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/378\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"c85ccde8-236f-11e5-be7f-f8b156bec77a",
         "originalFilename":"test.png",
         "mimetype":"image\/jpeg",
         "size":114281,
         "extension":"png"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/379\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"262d1aa4-2370-11e5-9f54-f8b156bec77a",
         "originalFilename":"kappe.png",
         "mimetype":"image\/png",
         "size":37141,
         "extension":"png"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/380\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"3c888720-2370-11e5-b867-f8b156bec77a",
         "originalFilename":"gw3ROhXR.jpg",
         "mimetype":"image\/jpeg",
         "size":32796,
         "extension":"jpeg"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/381\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"559e5b4a-2370-11e5-b92d-f8b156bec77a",
         "originalFilename":"gw3ROhXR.jpg",
         "mimetype":"image\/jpeg",
         "size":32796,
         "extension":"jpeg"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/382\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"6fb5577c-2370-11e5-9686-f8b156bec77a",
         "originalFilename":"Zahlungseingang2.png",
         "mimetype":"image\/png",
         "size":37431,
         "extension":"png"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/383\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"f7b5cf4e-2370-11e5-b36c-f8b156bec77a",
         "originalFilename":"CD7w1-_UIAAldNn.jpg",
         "mimetype":"image\/jpeg",
         "size":119472,
         "extension":"jpeg"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/384\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"d9699fe0-2373-11e5-a018-f8b156bec77a",
         "originalFilename":"744px-Deutsche_Bahn_AG-Logo.svg.png",
         "mimetype":"image\/png",
         "size":18381,
         "extension":"png"
      },
      {
         "@id":"\/~felicitus\/PartKeepr\/web\/app_dev.php\/api\/manufacturer_i_c_logo\/385\/getImage",
         "@type":"ManufacturerICLogo",
         "type":"iclogo",
         "filename":"ee01989c-2376-11e5-88aa-f8b156bec77a",
         "originalFilename":"gw3ROhXR.jpg",
         "mimetype":"image\/jpeg",
         "size":32796,
         "extension":"jpeg"
      }
   ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions