Skip to content

Instantly share code, notes, and snippets.

@taybin
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taybin/c5e343c16525b4d6265c to your computer and use it in GitHub Desktop.
Save taybin/c5e343c16525b4d6265c to your computer and use it in GitHub Desktop.
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