Field has no unique constraint


#1

I tried to define the following types:

entity type A {
  id: string
  code: string,
  linkToB: B (code, code)
}

entity type B {
  id: string
  code:  string
}

I got the following error during provision

One to one or many to one fkey field Transform.linkToB references field B.code which has no unique constraint.

What does this error mean?


#2

Currently your type definitions allow for many objects of type B with the same value in the code field. Therefore the linkToB field should be defined as an array

entity type A {
  code: string
  linkToB: [B] (code, code)
}

entity type B {
  code:  string
}

Alternatively, you could impose a uniqueness constraint on the code field of type B, enforcing that only 1 object of type B can exist with a particular value of code

entity type A {
  code: string
  linkToB: B (code, code)
}

@db(unique=['code'])
entity type B {
  code:  string
}