0

I'm trying to create a TypeDef with two fields unique restriction. I know it's possible to do it in the interface of faunaDB Console as you can see in this image, but I want to do it using a schema.

My current (not working) code, thats only assigns the first variable (in this case "promo") to the created index:

type PromoTemplateVariable {
    promo: Promo! @unique(index: "unique_promo_variable")
    variable: TemplateVariable! @unique(index: "unique_promo_variable")
    value: String!
}
Lenik
  • 63
  • 5

1 Answers1

2

Using FaunaDB Shell:

CreateIndex({
  name:   "unique_promo_variable",
  source: Collection("PromoTemplateVariable"),
  terms: [
    {
      field: ["data", "promo"]
    },
    {
      field: ["data", "variable"]
    }
  ],
  unique: true
})

It's the only way I've found to do this until they implement this feature in the @unique directive

Lenik
  • 63
  • 5