Get data from previous changeset

Hi to all!
I have the set of data for airports tickets:

%{
  class: "economy",
  legs: [
    %{date: "2018-08-01", from: ["FRA"], to: ["LON"]},
    %{date: "2018-08-10", from: ["LON"], to: ["FRA"]}
  ],
  passengers: %{adults: 1, children: 0, infants: 0}
}

I am using cast_assoc for legs:

...
|> cast(attrs, [:passengers, :class])
|> cast_assoc(:legs)
...

I need to check that the dates in the right order (date of first flight needs to be before the date of second flight). How can I get the value of date previous changeset?

You can use Ecto.Changeset.validate_change/4 on the :legs field.

1 Like

You damn right!
Thank you very much!
Sorry, I did not know that I can use ‘validate_change’ on the field like ‘legs’.