View Source EctoShorts.CommonChanges (ecto_shorts v1.1.2)

This module is responsible for determining put/cast assoc as well as creating and updating model relations

Link to this section Summary

Functions

Checks if field on changeset is empty list in data or changes

Checks if field on changeset is nil in data or changes

Preloads changeset assoc and put_or_cast's it, should use this most of time See docs for EctoShorts.CommonChanges.put_or_cast_assoc/3 for ideas on how it works and what you can pass

Preloads a changesets association

Determines put or cast on association with some special magic

Run's changeset function if when function returns true

Link to this section Functions

Link to this function

changeset_field_empty?(changeset, key)

View Source

Specs

changeset_field_empty?(Ecto.Changeset.t(), atom()) :: boolean()

Checks if field on changeset is empty list in data or changes

Link to this function

changeset_field_nil?(changeset, key)

View Source

Specs

changeset_field_nil?(Ecto.Changeset.t(), atom()) :: boolean()

Checks if field on changeset is nil in data or changes

Link to this function

preload_change_assoc(changeset, key)

View Source

Specs

preload_change_assoc(Ecto.Changeset.t(), atom()) :: Ecto.Changeset.t()
Link to this function

preload_change_assoc(changeset, key, opts)

View Source

Specs

preload_change_assoc(Ecto.Changeset.t(), atom(), Keyword.t()) ::
  Ecto.Changeset.t()

Preloads changeset assoc and put_or_cast's it, should use this most of time See docs for EctoShorts.CommonChanges.put_or_cast_assoc/3 for ideas on how it works and what you can pass

Link to this function

preload_changeset_assoc(changeset, key, opts \\ [])

View Source

Specs

preload_changeset_assoc(Ecto.Changeset.t(), atom(), [integer()]) ::
  Ecto.Changeset.t()

Preloads a changesets association

Link to this function

put_or_cast_assoc(changeset, key, opts \\ [])

View Source

Specs

put_or_cast_assoc(Ecto.Changeset.t(), atom(), Keyword.t()) :: Ecto.Changeset.t()

Determines put or cast on association with some special magic

If you pass a many to many relation only a list of id's it will count that as a member_update and remove or add members to the relations list

E.G. User many_to_many Fruit

This would update the user to have only fruits with id 1 and 3

CommonChanges.put_or_cast_assoc(change(user, fruits: [%{id: 1}, %{id: 3}]), :fruits)
Link to this function

put_when(changeset, when_func, change_func)

View Source

Specs

Run's changeset function if when function returns true