diff --git a/packages/strapi-plugin-content-manager/services/utils/configuration/index.js b/packages/strapi-plugin-content-manager/services/utils/configuration/index.js index b470b25497..8550aa7bc7 100644 --- a/packages/strapi-plugin-content-manager/services/utils/configuration/index.js +++ b/packages/strapi-plugin-content-manager/services/utils/configuration/index.js @@ -24,6 +24,7 @@ async function createDefaultConfiguration(model) { // convert model to schema const schema = formatContentTypeSchema(model); + schema.primaryKey = model.primaryKey; if (model.config) { await validateCustomConfig(model, schema); @@ -40,6 +41,7 @@ async function createDefaultConfiguration(model) { async function syncConfiguration(conf, model) { // convert model to schema const schema = formatContentTypeSchema(model); + schema.primaryKey = model.primaryKey; if (model.config) { await validateCustomConfig(model, schema); diff --git a/packages/strapi-plugin-content-manager/services/utils/configuration/metadatas.js b/packages/strapi-plugin-content-manager/services/utils/configuration/metadatas.js index ed1a8626b3..4df369e8e4 100644 --- a/packages/strapi-plugin-content-manager/services/utils/configuration/metadatas.js +++ b/packages/strapi-plugin-content-manager/services/utils/configuration/metadatas.js @@ -29,11 +29,11 @@ function createDefaultMetadatas(schema) { function createDefaultMainField(schema) { if (!schema) return 'id'; - return ( - Object.keys(schema.attributes).find( - key => schema.attributes[key].type === 'string' - ) || 'id' + const mainField = Object.keys(schema.attributes).find( + key => schema.attributes[key].type === 'string' && key !== schema.primaryKey ); + + return mainField || 'id'; } function createDefaultMetadata(schema, name) { @@ -150,7 +150,10 @@ const getTargetSchema = (name, plugin) => { const model = strapi.getModel(name, plugin); if (!model) return null; - return formatContentTypeSchema(model); + return { + ...formatContentTypeSchema(model), + primaryKey: model.primaryKey, + }; }; module.exports = {