I managed to save it with the correct values after adding category_id and mood_id to the cast function!
I edited the Main get_activity function to preload the relationships:
def get_activity!(id) do
Repo.get!(Activity, id)
+ |> Repo.preload([:category, :mood])
end
After inspecting the object when showing it I get this:
%Main.Activity{
__meta__: #Ecto.Schema.Metadata<:loaded, "activities">,
category: %Flytte.Main.Categories{
__meta__: #Ecto.Schema.Metadata<:loaded, "categories">,
activities: #Ecto.Association.NotLoaded<association :activities is not loaded>,
color: "#000000",
id: 2,
inserted_at: ~N[2022-01-01 19:39:45],
name: "Sleep",
updated_at: ~N[2022-01-01 19:39:45]
},
category_id: 2,
datetime_end: ~N[2017-01-01 00:00:00],
datetime_start: ~N[2017-01-01 00:00:00],
id: 8,
inserted_at: ~N[2022-01-01 22:15:28],
mood: %Flytte.Main.Moods{
__meta__: #Ecto.Schema.Metadata<:loaded, "moods">,
activities: #Ecto.Association.NotLoaded<association :activities is not loaded>,
emoji: ":)",
id: 2,
inserted_at: ~N[2022-01-01 19:43:52],
name: "Fine",
updated_at: ~N[2022-01-01 19:43:52]
},
mood_id: 2,
name: "Test5",
updated_at: ~N[2022-01-01 22:15:28]
}
Please note that there is a category but also category_id, It this ok, to have these 2 values there? Shouldn’t it be only one?






















