kaffy
kaffy copied to clipboard
accept value_fn for {:array, _} field
This change will allow to define a :value_fn for any {:array, _} field. I use it as work-around for many_to_many associations. What I do is adding the field in the Kaffy.MyModelAdmin.form_fields/1
def form_fields(schema) do
Kaffy.ResourceSchema.form_fields(schema)
|> Keyword.put(:associated_entities, %{
type: {:array, :integer},
value_fn: fn model ->
Repo.preload(model, [:other_entities])
|> Map.get(:other_entities)
|> Enum.map(& &1.id)
end,
values_fn: fn _, _ ->
Repo.all(Models.Entity)
|> Enum.map(&{&1.name, &1.id})
end
})
end
Hi,
Thanks for your contribution!
Is this still required and works on the latest version?
Gavin.