Role.firstWhere()
Learn: Roles |
---|
Get the first matching accessible role.
Signature
Role.firstWhere(predicate: () => Boolean)) => Role | NullRole
Role.firstWhere(predicate: (val: Role) => Boolean)) => Role | NullRole
Description
Each role in a Fauna is represented by a Role
document. This method returns
a Role
for the first accessible role that matches the predicate function.
Staged schema
If a database has staged schema, this method interacts with documents for the staged schema, not the database’s active schema.
For more information, see Run a staged schema change.
Parameters
Examples
Role.firstWhere(.name.includes("manager"))
{
name: "manager",
coll: Role,
ts: Time("2099-07-27T22:40:32.735Z"),
privileges: [
{
resource: "Store",
actions: {
create: true,
read: true,
write: true,
delete: true
}
},
...
{
resource: "Manager",
actions: {
read: "(ref) => Query.identity() == ref"
}
}
],
membership: [
{
resource: "Manager"
}
]
}
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!