I get this warning when casting
warning: casting embeds with cast/4 is deprecated, please use cast_embed/3 instead
I have the model Organization
defmodule Bonsai.Organization do
use Bonsai.Web, :model
alias Bonsai.OrganizationSettings
schema "organizations" do
field :name, :string
field :currency, :string
field :tenant, :string
field :info, :map, default: %{}
embeds_one :settings, OrganizationSettings, on_replace: :delete
timestamps
end
@required_fields ~w(name currency tenant)
@optional_fields ~w(info settings)
@doc """
"""
def changeset(model, params \\ %{}) do
cast(model, params, @required_fields, @optional_fields)
|> cast_embed(:settings)
|> put_embed(:settings, OrganizationSettings.changeset(%OrganizationSettings{}, params[:settings] || %{}))
|> change(%{info: params[:info] || %{}})
end
end
And my embedded model OrganizationSettings
defmodule Bonsai.OrganizationSettings do
use Ecto.Model
#use Ecto.Changeset
@primary_key {:id, :binary_id, autogenerate: true}
#schema "" do
embedded_schema do
field :show_search_on_focus, :boolean, default: true
field :theme, :string, default: "bonsai"
end
def changeset(model, params \\ %{}) do
model
|> cast(params, [:theme], [:show_search_on_focus])
|> validate_inclusion(:theme, ["bonsai", "dark"])
end
end
I have tried many ways but I'm doing something wrong please help