Git Product home page Git Product logo

Comments (5)

akserikawa avatar akserikawa commented on July 4, 2024

This is the PUT request I'm making right after creating one translation with en locale:

PUT /products/e6a43c5f-3a94-4fb9-9cc7-fac72ada4bc6

{
  "translations": {
    "en": {
      "id": 1,
      "title": "New title",
      "locale": "en"
    }
  }
}

And here are the Doctrine logs for that request:

[2021-01-13T22:34:42.239446+00:00] doctrine.DEBUG: SELECT t0.id AS id_1, t0.title AS title_2, t0.locale AS locale_3, t0.translatable_id AS translatable_id_4 FROM products_translations t0 WHERE t0.translatable_id = ? [{"Symfony\\Component\\Uid\\UuidV4":"e6a43c5f-3a94-4fb9-9cc7-fac72ada4bc6"}] []
[2021-01-13T22:34:42.243531+00:00] doctrine.DEBUG: SELECT NEXTVAL('products_translations_id_seq') [] []
[2021-01-13T22:34:42.245219+00:00] doctrine.DEBUG: "START TRANSACTION" [] []
[2021-01-13T22:34:42.245527+00:00] doctrine.DEBUG: INSERT INTO products_translations (id, title, locale, translatable_id) VALUES (?, ?, ?, ?) {"1":2,"2":"New title","3":"en","4":{"Symfony\\Component\\Uid\\UuidV4":"e6a43c5f-3a94-4fb9-9cc7-fac72ada4bc6"}} []
[2021-01-13T22:34:42.246025+00:00] doctrine.DEBUG: DELETE FROM products_translations WHERE id = ? [1] []
[2021-01-13T22:34:42.246313+00:00] doctrine.DEBUG: "COMMIT" [] []

As you can see, it's always trying to create new records and it's also deleting every existing translation for that product.
Am I doing something wrong here? Has someone experienced the same problem?
According to the docs, this should be a straight forward step but, somehow it's kinda messy.
Any help on this would be much appreciated.

from apiplatformtranslationbundle.

akserikawa avatar akserikawa commented on July 4, 2024

Btw, I'm running PHP 8.0.0 on API Platform v2.6-beta.1 and PostgreSQL 12.4

from apiplatformtranslationbundle.

paullla avatar paullla commented on July 4, 2024

Hi @akserikawa, this is the default behaviour of the new version of ApiPlatform. PUT replaces the object with the new one. Try to using PATCH for editing translations. More info for operations: https://api-platform.com/docs/core/operations/

from apiplatformtranslationbundle.

MarioZ2002 avatar MarioZ2002 commented on July 4, 2024

@akserikawa i was struggling with the same problem. i fixed it by providing the iri of the translation entity instead of the id.

{
  "translations": {
    "en": {
      "@id": "/product_translations/1",
      "title": "New title",
      "locale": "en"
    }
  }
}

@paullla im pretty sure that PUT Requests are not doing a delete/insert. It will do an update.

From the docs:
Note: Current PUT implementation behaves more or less like the PATCH method. Existing properties not included in the payload are not removed, their current values are preserved. To remove an existing property, its value must be explicitly set to null.

from apiplatformtranslationbundle.

paullla avatar paullla commented on July 4, 2024

Hey @MarioZ2002 , thanks for the input. The flow might have changed in the newer versions, I will research it to see if everything still works ok with the translations.

from apiplatformtranslationbundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.