Trying to use cast/3 function but it keeps telling me the cast/3 function is undefined

I am trying to follow an ecto embedded schema example from 2017 where the example uses the cast/3 function but it keeps telling me the cast/3 function is undefined.

Apparently the example uses “Ecto” and my app uses “phoenix_ecto” as the only difference i’ve been able to dectect.

the 2017 example apparently used “ecto” as a dependency… is that sill the norm?

Thanks for your help

From which module you are calling cast? Because Ecto.Changeset still has it: Ecto.Changeset — Ecto v3.10.1

Make sure your code has import Ecto.Changeset if the example’s does - if that was missing, it’d produce exactly an “undefined function cast/3” error in code that expects it.

thanks guys, the import is missing and will include it next.

the question still remains, is there an “ecto” dep besides the “phoenix_ecto”

Thanks again, this really helps my understanding of the ecto module… the example is great as it breaks down the use of embedded schemas very nicely…

defp deps do
      {:phoenix, "~> 1.7.2"},
      {:phoenix_ecto, "~> 4.4"},
      {:ecto_sql, "~> 3.6"},
      {:postgrex, ">= 0.0.0"},

this module is not on the deps list, do I need to add it?

the import Ecto.Changeset resolved the issue, thanks…

This is a rather basic Elixir construct. IMO you shouldn’t attempt complete workable examples before going through the tutorial.

1 Like

No it is a transitive dependency, so you don’t need to include it.

1 Like

Can you not just use this?

I imagine it will have more up to date information than something from 2017