RequireAssociations.Associations (ecto_require_associations v0.1.1)

Link to this section Summary

Functions

Turns a set of associations (as used by Ecto's preload) into a list of paths to that association. Examples are most helpful for understanding this. Imagine we have the following schemas

Link to this section Functions

Link to this function

paths(definitions)

Turns a set of associations (as used by Ecto's preload) into a list of paths to that association. Examples are most helpful for understanding this. Imagine we have the following schemas:

defmodule User do

use Ecto.Schema

schema "users" do
  belongs_to :region, Region
  has_many :roles, Role
end

end

defmodule Role do

use Ecto.Schema

schema "roles" do
  belongs_to :region, Region
end

end

iex> RequireAssociations.Associations.paths(:region) [[:region]]

iex> RequireAssociations.Associations.paths([:region, :roles]) [[:region], [:roles]]

iex> RequireAssociations.Associations.paths([:region, roles: :region]) [[:region], [:roles], [:roles, :region]]