mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 21:43:02 +12:00
1.2 KiB
1.2 KiB
Identities
Identities can be used to describe the ways that a resource is uniquely identified. For example, you may have a user resource that has an id
primary key, but is uniquely identifiable via the email
attribute as well.
To configure this, add an identities
block to your resource
For example:
identities do
identity :unique_email, [:email]
end
Effects
Identities are used in various ways across Ash and it's extensions. This list is not necessarily exhaustive:
Ash
- Identities can be used with
c:Ash.Api.get/3
, e.gMyApi.get(User, [email: "foo@bar.com"])
AshPostgres
- The migration generator creates unique constraints for identities
AshJsonApi
- Get routes can be configured to use a specific identity, creating a route like
GET /users/foo@bar.com
AshGraphql
- Get queries and mutations can be configured to use a specific identity, to create a query like the following. (Arbitrary filtering is supported on list queries, this is is for creating queries that return a single result)
query{
getUser(email: "foo@bar.com"){
id
}
}