Create a gist now

Instantly share code, notes, and snippets.

defmodule Node do
use Ecto.Model
schema "nodes" do
has_many :children, NodeToNode, foreign_key: :parent_id
has_many :parents, NodeToNode, foreign_key: :child_id
end
end
defmodule NodeToNode do
use Ecto.Model
schema "node_to_node", primary_key: false do
belongs_to :parent, Node, foreign_key: :parent_id
belongs_to :child, Node, foreign_key: :child_id
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment