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!
}

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.