strapi-relation-names 1.2.1 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -267,6 +267,11 @@ const matchesRelation = (source, candidate, targetModelType) => {
267
267
  const applyLabel = (value, hydrated, runtime) => {
268
268
  const label = renderTemplate(runtime, hydrated);
269
269
  if (label) {
270
+ const isNestedTemplate = runtime.placeholders.some((placeholder) => placeholder.includes("."));
271
+ const isIdentityField = runtime.displayField === "id" || runtime.displayField === "documentId";
272
+ if (isNestedTemplate && isIdentityField) {
273
+ return { ...value, label };
274
+ }
270
275
  return { ...value, [runtime.displayField]: label };
271
276
  }
272
277
  if (runtime.displayField === runtime.originalMainField) {
@@ -451,7 +456,11 @@ const relationLabels = ({ strapi }) => {
451
456
  }
452
457
  const editMetadata = isRecord$1(metadata.edit) ? metadata.edit : {};
453
458
  const configuredMainField = typeof editMetadata.mainField === "string" ? editMetadata.mainField : "id";
454
- const displayField = compiled.placeholders.some((placeholder) => placeholder.includes(".")) ? configuredMainField : compiled.displayField;
459
+ const isNestedTemplate = compiled.placeholders.some(
460
+ (placeholder) => placeholder.includes(".")
461
+ );
462
+ const isIdentityField = configuredMainField === "id" || configuredMainField === "documentId";
463
+ const displayField = isNestedTemplate && isIdentityField ? "label" : isNestedTemplate ? configuredMainField : compiled.displayField;
455
464
  metadatas[fieldName] = {
456
465
  ...metadata,
457
466
  edit: {
@@ -265,6 +265,11 @@ const matchesRelation = (source, candidate, targetModelType) => {
265
265
  const applyLabel = (value, hydrated, runtime) => {
266
266
  const label = renderTemplate(runtime, hydrated);
267
267
  if (label) {
268
+ const isNestedTemplate = runtime.placeholders.some((placeholder) => placeholder.includes("."));
269
+ const isIdentityField = runtime.displayField === "id" || runtime.displayField === "documentId";
270
+ if (isNestedTemplate && isIdentityField) {
271
+ return { ...value, label };
272
+ }
268
273
  return { ...value, [runtime.displayField]: label };
269
274
  }
270
275
  if (runtime.displayField === runtime.originalMainField) {
@@ -449,7 +454,11 @@ const relationLabels = ({ strapi }) => {
449
454
  }
450
455
  const editMetadata = isRecord$1(metadata.edit) ? metadata.edit : {};
451
456
  const configuredMainField = typeof editMetadata.mainField === "string" ? editMetadata.mainField : "id";
452
- const displayField = compiled.placeholders.some((placeholder) => placeholder.includes(".")) ? configuredMainField : compiled.displayField;
457
+ const isNestedTemplate = compiled.placeholders.some(
458
+ (placeholder) => placeholder.includes(".")
459
+ );
460
+ const isIdentityField = configuredMainField === "id" || configuredMainField === "documentId";
461
+ const displayField = isNestedTemplate && isIdentityField ? "label" : isNestedTemplate ? configuredMainField : compiled.displayField;
453
462
  metadatas[fieldName] = {
454
463
  ...metadata,
455
464
  edit: {
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "author": "Christoph Tupi <christoph.tupi@gmail.com>",
6
6
  "keywords": [],
7
7
  "type": "commonjs",
8
- "version": "1.2.1",
8
+ "version": "1.2.2",
9
9
  "strapi": {
10
10
  "kind": "plugin",
11
11
  "name": "strapi-relation-names",