[FEATURE-REQUEST] Support schemas that implement custom Phoenix.Param protocol
- Vorherrschende Sprache
- Elixir
- Sterne
- 1.4k
- Forks
- 171
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
**Describe the problem you're proposing to solve**
When a schema implements Phoenix.Param, links in the admin panel go to a path containing the custom param. However, Kaffy tries to use this custom param as an `:id` when querying the database. This results in the error:
```ex
deps/kaffy/lib/kaffy/resource_query.ex:49: value `"my-custom-param"` cannot be dumped to type :binary_id in query:
```
**Describe the solution you'd like**
How I've solved this in other admin panels (specifically, using Torch) is to add a virtual field to the schema definition (something along the lines of `:param_context`) that gets populated to `:admin` when the admin backend queries for records of that schema.
Then, in the `defimpl` for the struct, the library user can match on this virtual field. In the case that the `:param_context` is set to `:admin`, the implementing function can return the `:id`, allowing the admin backend to use the result like it would any other.
**Describe alternatives you've considered**
An alternative could be to offer full support for custom params, potentially via a new protocol: `Kaffy.Param`, which requires implementing a `from_param/1` function and returns the correct database field to query and a value to query for. Although, I like the idea of admin panels using database IDs exclusively instead of custom user-facing ones.
**Additional context**
* [Phoenix.Param](https://hexdocs.pm/phoenix/Phoenix.Param.html)
* Related, on the handling of non-standard IDs: https://github.com/aesmail/kaffy/issues/6
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.