Get entire collection data from relation widget

Hello,

I’m trying to get all fields from a collection referenced in a relation widget field, not just the single value declared in “valueField”. Is there any way to do this?

Thanks.

This is my current configuration:

collections:
    - label: Child
      name: child
      folder: child
      fields:
           - label: Name
            name: title
            widget: string

           - label: Age
            name: age
            widget: number

    - label: Father
      name: father
      folder: father
      fields:
          - label: Name
            name: title
            widget: string

          - label: Children
            name: children
            widget: list
            fields:
                - label: Child
                  name: child
                  widget: relation
                  collection: child
                  valueField: title

Not at this time. The relation widget currently only stores the value of the one named field.

Thanks. Is there any known workaround?

Can you give some details of what you are trying to do with the relation value and why you want all the relation fields to exist in the data rather than just resolve the data from the value at the time you access the data?

Like my example, I would like to get Name and Age from the children when I query a Father. I was looking for a more elegant to get this info than querying all Child and run it in a loop to compare strings and “attach” to the Father collection.

Generally you store a unique value, which may need to be an actual id string to ensure uniqueness, and then fetch related data at build time. Otherwise you would be storing duplicate data.

Got it. Thanks.

If it’s useful for anyone with the same question, what I did was create a datetime widget with format: x and set this field as identifier_field. This way I could fetch which Child was stored in Father.

1 Like