Mar 5, 2022
PageManager 9.5.2 For Free.. Documents when your scan your entire file organization structure from the overall
Presto! PageManager 9.5.2. Part of the Presto! Software Library for free. A world of experience, an excellent software program.
Q:
Placing *multiple* files using config.exs in Ecto.Changeset
I'm creating a custom changeset for a Recipe I'm making for an e-Shop. I need to add a few files (one for each category) to my changeset, but I don't know how to do this using the functions on the ecto.changeset documentation.
My changeset looks like this:
# recipe.changeset
defmodule Recipe.Changeset do
use Ecto.Changeset
@files "image.png"
@files "large_image.png"
@files "image.jpg"
def changeset(recipe, attrs \ %{}) do
changeset =
recipe
|> cast(attrs, @files)
|> validate_required([:file_name])
|> validate_inclusion(:file_name, ~w(image.png image.jpg large_image.png))
changeset
end
end
Which of course gives me an error:
[error] #PID running __MODULE__.__DIR__/../lib/recipe.ex:9: cannot cast Ecto.File to Ecto.Changeset.File
For reference, here is the code I'm working on, it's currently just the two changesets that are needed (Recipe.Changeset and Category.Changeset).
# recipe.changeset
defmodule Recipe.Changeset do
use Ecto.Changeset
def changeset(recipe, attrs) do
attrs =
case attrs do
%{id: id, ingredients: %{}} ->
attrs
%{ be359ba680
Related links:
Comments