static-cms icon indicating copy to clipboard operation
static-cms copied to clipboard

Summary field of relation field

Open DynamicsNinja opened this issue 1 year ago • 5 comments

Example:

Time (Collection)

  • Id
  • Name
  • Type

Ticket (Collection)

  • Id
  • Type (Relation of Time)
  • Price

When showing summary for ticket I want to show Name field of Time instead of ID field which is defined as value_field on relation on Ticket.

collections: [
    {
      name: "ticket",
      label: "Ticket",
      folder: "content/tickets",
      create: true,
      editor: {
        preview: false,
      },
      format: "json",
      identifier_field: "id",
      summary_fields: ["type", "price"],
      slug: "{{id}}",
      fields: [
        {
          label: "Id",
          name: "id",
          widget: "uuid",
        },
        {
          label: "Type",
          name: "type",
          widget: "relation",
          collection: "time",
          value_field: "id",
          search_fields: ["name"],
          display_fields: ["name"],
          options_length: 100,
          required: false,
        },
        { label: "Price", name: "price", widget: "number" },
      ],
    },
    {
      name: "time",
      label: "Time",
      folder: "content/time",
      create: true,
      editor: {
        preview: false,
      },
      icon: "house",
      identifier_field: "name",
      summary_fields: ["name", "type"],
      i18n: true,
      format: "json",
      fields: [
        { label: "Id", name: "id", widget: "uuid", i18n: false },
        { label: "Name", name: "name", widget: "string", i18n: true },
        {
          label: "Type",
          name: "type",
          widget: "select",
          options: ["Krugovi", "Vrijeme"],
          i18n: false,
          required: false,
        },
      ],
    },
  ]

DynamicsNinja avatar Nov 10 '23 10:11 DynamicsNinja

I understand what you are wanting to do, but not sure where your issue is. What is happening when you us your config right now?

KaneFreeman avatar Nov 10 '23 18:11 KaneFreeman

I see the ticket summary as:

Type Price
ff36cbc3-9dc0-4208-8a43-0e1589837aba 25
db54561c-9c1f-470d-9f13-321568805461 30

And I would like to see it in a user-friendly way

Type Price
Type 1 25
Type 2 30

DynamicsNinja avatar Nov 11 '23 14:11 DynamicsNinja

Ah, I see. You want to use the summary of the related collection (Time) in the table of Tickets. I will have to look into the feasibility of that.

KaneFreeman avatar Nov 17 '23 15:11 KaneFreeman

So it looks like this can be achieved partially with minor impact. When using the summary_fields it will try to get a proper summary for relation fields. However, it will not work in Template Transformations right now. I will push this out in the next release.

KaneFreeman avatar Nov 17 '23 17:11 KaneFreeman

I still can't achieve this even with v4. What exactly do I need to change in my original snippet of collections to make it work?

DynamicsNinja avatar Jan 19 '24 12:01 DynamicsNinja