Role.create()

Create a role.

Signature

Role.create(data: {*: Any}): Role

Description

This method adds a new role to the Role collection and returns the corresponding Role. The maximum number of overlapping roles is 64. Attempts to create the sixty-fifth overlapping role result in an error.

Parameters

Parameter Type Required Description

data

Object

Yes

Object describing the role.

data fields

Name Type Required Description

name

String

Yes

A unique name.

privileges

Array

Yes

One or more privilege configuration objects.
See Privilege configuration object

membership

Array

One or more membership configuration objects.
See Membership configuration object

data

Object

User-defined metadata that stores supplemental information.

Return value

Type Description

Role

A Role representing the role.

Examples

Role.create({
    name: "mgmtTeam",
    membership: [
    {resource: "People"}],
    privileges: [{
      resource: "CoffeeBean",
      actions: {
        read: true
      }
    }, {
      resource: "Customers",
      actions: {
        create: true
      }
    }],
    data: {
      custom: "some data"
    }
  })
{
  name: "mgmtTeam",
  coll: Role,
  ts: Time("2023-07-27T21:59:03.480Z"),
  privileges: [
    {
      resource: "CoffeeBean",
      actions: {
        read: true
      }
    },
    {
      resource: "Customers",
      actions: {
        create: true
      }
    }
  ],
  membership: [
    {
      resource: "People"
    }
  ],
  data: {
    custom: "some data"
  }
}

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!