Remove primarykey from possible mainField with string type

This commit is contained in:
Alexandre Bodin 2019-11-21 11:49:29 +01:00
parent 6f82a4ea48
commit 7f90bdb5b9
2 changed files with 10 additions and 5 deletions

View File

@ -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);

View File

@ -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 = {