Last active
August 29, 2015 14:07
-
-
Save taybin/c5e343c16525b4d6265c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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