Elixir Ecto:Arborを使ってPostgresqlで隣接リストとツリーのエルゴードを実現します.
1852 ワード
Arborプロジェクトアドレス
CTEsとは何ですか
CTEctoの隣接リストとツリーのエルゴードをCTEctoを使用して実現し、
使用
現在のノードの先のノードを取得し、親の世代のノードを下のインターネットからすべて返します.主に分類ナビゲーションパスを表示するために使用されます.
現在のノードのすべての後裔ノードを取得し、後代ノードリストに戻る.
現在のノードのすべてのサブノードを取得します.
現在のノードの親ノードを取得 に設定されている. を設定する. です. です. です. です. が実装されていません.
CTEsとは何ですか
CTEctoの隣接リストとツリーのエルゴードをCTEctoを使用して実現し、
Arbor
を使用して簡単なツリー構造を作成する.使用
defmodule Comment do
use Ecto.Schema
# See config options below
use Arbor.Tree, foreign_key_type: :binary_id
schema "comments" do
field :body, :string
belongs_to :parent, Arbor.Comment
timestamps
end
end
ルートノードを取得roots = Comment.roots
|> Repo.all
兄弟ノードを取得siblings = my_comment
|> Comment.siblings
|> Comment.order_by_popularity
|> Repo.all
祖先ノードを取得現在のノードの先のノードを取得し、親の世代のノードを下のインターネットからすべて返します.主に分類ナビゲーションパスを表示するために使用されます.
descendants = my_comment
|> Comment.ancestors
|> Comment.order_by_inserted_at
|> Repo.all
次のノードを取得現在のノードのすべての後裔ノードを取得し、後代ノードリストに戻る.
descendants = my_comment
|> Comment.descendants
|> Comment.order_by_inserted_at
|> Repo.all
サブノードを取得現在のノードのすべてのサブノードを取得します.
children = my_comment
|> Comment.children
|> Repo.all
親ノードを取得現在のノードの親ノードを取得
parent = my_comment
|> Comment.parent
|> Repo.first
オプションparent_id
は、CTEsで使用するテーブル名CTEs
はCTEの名前Breadcrumbs
デフォルトは、Ectoからのtable_name
モジュール属性tree_name
デフォルトは、Ectoからのprimary_key
モジュール属性@primary_key
のデフォルトはprimary_key_type
@primary_key
デフォルトは、Ectoからのforeign_key
モジュール属性parent_id
のデフォルトはforeign_key_type
で、現在は