Open glacierck opened 8 months ago
I have made some modifications to the source code to address the issue I mentioned earlier. I'm not sure if it will introduce any unknown issues.
const updateOrCreate = async (user, slug, data, idField = 'id') => {
const relationAttributes = getModelAttributes(slug, { filterType: ['component', 'dynamiczone', 'media', 'relation'] });
for (let attribute of relationAttributes) {
data[attribute.name] = await updateOrCreateRelation(user, attribute, data[attribute.name]);
}
let entry;
const model = getModel(slug);
// fix
const _idField = model?.pluginOptions?.['import-export-entries']?.idField || idField;
if (model.kind === 'singleType') {
entry = await updateOrCreateSingleType(user, slug, data, _idField);
} else {
entry = await updateOrCreateCollectionType(user, slug, data, _idField);
}
return entry;
};
During the test, I discovered another issue. When importing relationship type attributes first and then non relationship attributes, the relationship attributes will be deleted, but the reverse order of operations will not cause overwriting or deletion.
@glacierck version 1.23.1 should fix the issue. I updated how relations are retrieved from database in code
@Baboo7 strapi-plugin-import-export-entries/src/server/services/import/import.js Has the revision here been considered
@glacierck version 1.23.1 should fix the issue. I updated how relations are retrieved from database in code
Thank you very much, the new version is effective. Solved the problem of secondary import data overwriting old relationships.
Hope the next version can also solve another problem, so that I don't need to invade the source code anymore.
Describe the bug When importing data involving relationship types, even if the other party of the relationship has defined idField, it still fails to import due to the lack of id field selection for creation
To Reproduce age_groups schema.json
{ "collectionName": "age_groups", "pluginOptions": { "import-export-entries": { "idField": "title" } }, "attributes": { "title": { "type": "string", "unique": true, "required": true, "maxLength": 8 } } }
import data
[ { "id": 1, "title": "some", "genders": "female", "ages": [{"title" : "youth"}] }]
output "error": "insert into \"public\".\"age_groups\" (\"created_at\", \"created_by_id\", \"title\", \"updated_at\", \"updated_by_id\") values ($1, $2, $3, $4, $5) returning \"id\" - duplicate key value violates unique constraint \"age_groups_pkey\"",
Expected behavior ages are connected to age_groups model, I hope to import data that can be connected to existing data in a relationship rather than creating new age records