Comments (5)
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.
Btw, I'm running PHP 8.0.0
on API Platform v2.6-beta.1
and PostgreSQL 12.4
from apiplatformtranslationbundle.
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.
@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.
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)
- Uncaught Error: Return value of Locastic\ApiPlatformTranslationBundle\Model\AbstractTranslatable::getTranslations() must implement interface Doctrine\Common\Collections\Collection, null returned HOT 1
- Can't force certain locale HOT 1
- Translations create not working as expected when GraphQl is used HOT 1
- best practice to prevent the user from translating the same word in the same language
- inconsistency of returning types HOT 2
- Error on loading AliceBundleFixtures HOT 1
- The Symfony validator don't with this bundle HOT 1
- validation of the fields of my entity with PUT REQUEST HOT 2
- Loader Load Exception HOT 1
- OrderFilter on translated fields and a certain locale HOT 2
- editing object after increment 'Translation' id
- Automatically add translation when it does not exist HOT 4
- Force length 2 for locales HOT 5
- Filter on current locale translations
- support api-platform/core^3.0@rc HOT 1
- unique constraint " name + locale " HOT 2
- Usage question about Api Platforms json-response HOT 1
- New release? HOT 2
- Doctrine/orm 3 support HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apiplatformtranslationbundle.