View Source Backpex.Ecto.EctoUtils (Backpex v0.7.1)
Utilities for working with Ecto schemas and changesets.
Summary
Functions
Get the primary key field of an Ecto schema.
Functions
Get the primary key field of an Ecto schema.
This function can handle various input types:
- Ecto schema module
- Ecto schema struct
- Ecto.Changeset
Examples
iex> get_primary_key_field(MyApp.User)
:id
iex> get_primary_key_field(%MyApp.User{})
:id
iex> get_primary_key_field(Ecto.Changeset.change(%MyApp.User{}))
:id
Errors
Raises an error if:
- No primary key is defined
- A compound primary key is used (not supported)