update()

Update a Role.

Signature

update(object: {*: Any}): { *: Any }

Description

This method updates a role with the object fields and returns the updated document. During the update, fields from object are copied to the document, creating new fields or updating existing fields. The operation is similar to a merge.

Only the fields included in object are updated, all other document fields aren’t updated. Fields with nested objects in object are merged with the identically named nested object in the document.

Use the update() method to rename a role or update its user-defined metadata. To remove a field, set its value in object to null.

Parameters

Parameter Type Required Description

object

Role

Yes

Role document with the updated document fields.

Return value

Type Description

Object

Document with updated fields.

Examples

Role.byName("manager")?.update({
    membership: [
      {
        resource: "Manager"
      }
    ],
    privileges: [
      {
        resource: "Order",
        actions: {
          create: false,
          delete: false,
          read: true,
          write: false
        }
      }, {
        resource: "Product",
        actions: {
          create: true
        }
      }
    ],
    data: {
      custom: "some data"
    }
  })
{
  name: "manager",
  coll: Role,
  ts: Time("2023-07-27T22:40:32.735Z"),
  privileges: [
    {
      resource: "Order",
      actions: {
        create: false,
        delete: false,
        read: true,
        write: false
      }
    },
    {
      resource: "Product",
      actions: {
        create: true
      }
    }
  ],
  membership: [
    {
      resource: "Manager"
    }
  ],
  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!