Swiss.Ecto (swiss v3.12.0) View Source

Generic helper functions related with Ecto.

Link to this section Summary

Functions

Given an association field, returns whether it's preloaded.

Link to this section Functions

Link to this function

assoc_present?(assoc, accept_nil? \\ false)

View Source

Specs

assoc_present?(assoc :: term(), accept_nil? :: boolean()) :: boolean()

Given an association field, returns whether it's preloaded.

Examples

iex> Swiss.Ecto.assoc_present?(nil)
false

iex> Swiss.Ecto.assoc_present?(nil, true)
true

iex> Swiss.Ecto.assoc_present?(%Ecto.Association.NotLoaded{})
false

iex> Swiss.Ecto.assoc_present?([])
true

iex> Swiss.Ecto.assoc_present?(MapSet.new())
true