Closed Adzz closed 3 years ago
On reflection I wonder if a better way is to always have it optional on cast, and just have a validation for relations like so:
EctoMorph.generate_changeset(...)
|> EctoMorph.validate_required([my_relation: [:a_field, :another_one]])
|> EctoMorph.into_struct!()
This should work for generate_changeset and cast_to_struct really. It allows a user to cast to a struct, marking a relation as required on the way.
although now you could do:
Adding it to the top level of cast_to_struct means we could:
and have it fail if / when :relation is missing. Though not sure what the API should look like really.