View Source Flint.Extensions.Typed (Flint v0.6.0)
Adds supports for most of the features from the wonderful typed_ecto_schema library.
Rather than using the typed_embedded_schema macro from that library, however, thr Typed extension incorporates the features into the standard
embedded_schema macro from Flint.Schema, meaning even fewer lines of code changed to use typed embedded schemas!
Included with that are the addtional Schema-Level options
you can pass to the embedded_schema macro.
You also have the ability to override field typespecs as well as providing extra field-level options from
typed_ecto_schema.
Required vs Enforced vs Null
Note that the typespecs allow you to specify
:enforceand:nulloptions, which are different from the requirement imposed byfield!.
field!marks the field as being required during the changeset validation, which is equal to passing the field name to theEco.Changeset.validate_required/3. An instance of the schema's struct CAN still be created if a field marked withfield!is not present.
enforce: trueis equal to including that field in the@enforce_keysmodule attribute for the corresponding schema struct.An instance of the schema's struct CANNOT be created if a field marked with
enforce: trueis not present, as it willraiseanArgumentError.
:nullindicates whethernilis a valid value for the field. This only impacts the generated typespecs.