-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is cast_attachments changing my params? #5
Comments
Can you share your cast and cast_attachments code? Currently it is designed where you need to use cast_attachments for all file attributes only. All other attributes should still be sent through cast. |
This is my model. defmodule Mobil.Company do
use Mobil.Web, :model
use Arc.Ecto.Model
schema "companies" do
field :name, :string
field :logo, Mobil.Logo.Type
timestamps
end
@required_fields ~w(name)
@optional_fields ~w(logo)
@doc """
Creates a changeset based on the `model` and `params`.
If no params are provided, an invalid changeset is returned
with no validation performed.
"""
def changeset(model, params \\ :empty) do
model
|> cast_attachments(params, @required_fields, @optional_fields)
end
end So i need to split it up? |
Yes, please split it up as such: https://github.com/stavro/arc_ecto/blob/master/test/model_test.exs#L21 and try again |
Worked wonders! Thank you @stavro |
I will do some digging to see if there is a less confusing way to handle this... You are not the first person to make this same hiccup |
@stavro I don't know if i think that it is confusing, rather i would say the readme could be clearer. More specific. https://github.com/stavro/arc_ecto#add-your-attachment-to-your-ecto-model Which could explain it more like.. schema "companies" do
field :name, :string
field :logo, Mobil.Logo.Type
timestamps
end
@required_fields ~w(name)
@optional_fields ~w()
@doc """
Creates a changeset based on the `model` and `params`.
If no params are provided, an invalid changeset is returned
with no validation performed.
"""
def changeset(model, params \\ :empty) do
model
|> cast(params, @required_fields, @optional_fields)
|> cast_attachments(params, ~w(), ~w(logo))
end |
Readme updated! Thanks. |
When using cast_attachments/4, Phoenix seem to choke, with the following error, while rendering my form.
As Phoenix tries to render
Which suggest, that my name value was changed?
If i change it back to cast/4, then the problem is gone, but then i'm missing my image.
The text was updated successfully, but these errors were encountered: