coryodaniel / arbor

Ecto elixir adjacency list and tree traversal. Supports Ecto versions 2 and 3.
MIT License
239 stars 26 forks source link

Order Ancestors and Descendants By Depth By Default #32

Open millllllz opened 3 years ago

millllllz commented 3 years ago

This may be a personal preference, but I think this aligns more closely to similar projects.

coryodaniel commented 3 years ago

You should be able to pipe the operations into other statements:

    test "given a struct w/ returns its descendants" do
      [root | tail] = create_chatter("pupperinos")
      _cat_comments = create_chatter("kittehs")

      dog_thread =
        root
        |> Comment.descendants()
        |> Comment.by_inserted_at()
        |> Repo.all()

      assert dog_thread == tail
    end
millllllz commented 3 years ago

This may be an odd use case, but having an earlier inserted_at, doesn't necessarily indicate that the node is a parent. A new parent could be created and have the child added to it, for example.

coryodaniel commented 3 years ago

You should be able to pipe into any Ecto query (order, where, join, etc)

Thanks,

Cory O’Daniel

On Dec 3, 2020, at 11:48 AM, JasonMiller notifications@github.com wrote:

 This may be an odd use case, but having an earlier inserted_at, doesn't necessarily indicate that the node is a parent. A new parent could be created and have the child added to it, for example.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

coryodaniel commented 3 years ago

@JasonMiller circling back to this. Do you know if a default order by is set, will ecto overwrite that if someone pipes in an alternate order by or will it merge them?