Is it possible to retrieve the index value of an array item?

prisma

#1

So, I wish to return for every item added to an array, in my mutation/query, its index value. Is this possible? So for example, in my following type definitions, I wish to retrieve the index value of every item added to Size.

type ItemVariant {
  id: ID! @unique
  item: Item @relation(name: "VariantssOfItem") #relationship to Item. 
  size: [Size!]! @relation(name: "SizesOfItemVariant" onDelete: CASCADE)
  color: Color!
  quantity: Int! @default(value: "1")
  image: String
  largeImage: String
  sizelist: SizeList!
}

type Size {
  id: ID! @unique
  name: String!
  label: String
  quantity: Int! @default(value: "1")
  itemvariant: ItemVariant @relation(name: "SizesOfItemVariant") #relationship to ItemVariant. 
}

#2

Arrays do not exist in relational databases.

What you have created is a one to many relationship. We know there is a relationship between those pieces of data. We know there can be multiple Size records linked to a single ItemVariant records.

We do not know that there is a specific order to those sizes. In fact the order of the sizes is not guaranteed!

If you want to store an index you must do it yourself. One way would be to add an index field to the Size type.


#3

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.