Max length for accountRelation LIST

I have a model named “Profile” as the example below.

type Profile @createModel(accountRelation: LIST, description: "A profile") {
  ...
}

With this “LIST” relation, an author account can have unlimited profiles, but what I want to achieve is that one account can have at most 5 profiles. How can I achieve this?

Hi, the account relation doesn’t support arbitrary restrictions like this.
Though they are different in practice, one way to think of account relations is as SQL relations between tables, that can be one-to-many (“LIST” account relation) or one-to-one (“SINGLE” account relation), there is no “one-to-N” type of relation.

A possible alternative in your case could be to embed the profiles into a single document, where you can apply such restrictions, for example:

type Profile {
  name: String! @string(minLength: 3, maxLength: 50)
}

# Only one ProfilesContainer document can exist with the SINGLE account relation
type ProfilesContainer @createModel(accountRelation: SINGLE, description: "A restricted set of profiles") {
  profiles: [Profile!] @list(maxLength: 5) # At most 5 Profile objects can be added
}
1 Like

Thank you, this makes sense.

Hey Paul,

Using the example above, is it any way to have a unique constraint on the “name” property in the Profile?

Hi,
No, the model fields can’t support such constraints, only the account relation.

I see, thank you