arbor icon indicating copy to clipboard operation
arbor copied to clipboard

Order Ancestors and Descendants By Depth By Default

Open millllllz opened this issue 5 years ago • 4 comments

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

millllllz avatar Oct 07 '20 01:10 millllllz

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

coryodaniel avatar Dec 03 '20 19:12 coryodaniel

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.

millllllz avatar Dec 03 '20 19:12 millllllz

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 [email protected] 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 avatar Dec 03 '20 19:12 coryodaniel

@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?

coryodaniel avatar Jul 21 '21 17:07 coryodaniel