EctoContext.Validate (EctoContext v0.1.0)

Copy Markdown View Source

Validation helpers used by the EEx templates in priv/templates/ecto_context/.

These functions are called at runtime from code generated by EctoContext. They guard against invalid options and unknown associations before queries hit the database.

Summary

Functions

Validates that assoc_atom is a known association or _id field on module.

Validates that all keys in opts are in the valid_keys list.

Functions

validate_assoc!(module, assoc_atom)

@spec validate_assoc!(module(), atom()) :: :ok

Validates that assoc_atom is a known association or _id field on module.

Raises ArgumentError if neither a belongs_to association nor a corresponding _id field exists on the schema.

validate_opts!(opts, valid_keys)

@spec validate_opts!(
  keyword(),
  [atom()]
) :: :ok

Validates that all keys in opts are in the valid_keys list.

Raises ArgumentError listing the unsupported keys if any are found.