Sow.Schema (Sow v0.1.4)

Copy Markdown View Source

Helpers for introspecting Ecto schemas.

Summary

Functions

Get the association type for a field in a schema.

Get the foreign key for a has_many or has_one association.

Functions

association_type(schema, field)

@spec association_type(module(), atom()) ::
  :belongs_to | :has_many | :has_one | :many_to_many | nil

Get the association type for a field in a schema.

Returns:

  • :belongs_to for belongs_to associations
  • :has_many for has_many associations
  • :has_one for has_one associations
  • :many_to_many for many_to_many associations
  • nil if the field is not an association

foreign_key(schema, field)

@spec foreign_key(module(), atom()) :: atom() | nil

Get the foreign key for a has_many or has_one association.