Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with adding a child to a tree #15

Open
dreamfall opened this issue Mar 31, 2022 · 0 comments
Open

Problem with adding a child to a tree #15

dreamfall opened this issue Mar 31, 2022 · 0 comments

Comments

@dreamfall
Copy link

dreamfall commented Mar 31, 2022

Hi, I'm having troubles with adding a record as a child in tests:

defmodule SomeApp.Api.Node do
  use Ecto.Schema
  use AsNestedSet, scope: [:emotion_id]
end


root_node = %Node{emotion_id: emotion.id, name: "root"} |> AsNestedSet.create(:root) |> AsNestedSet.execute(Repo)
child_node = %Node{emotion_id: emotion.id, name: "asd"} |> AsNestedSet.create(root_node, :child) |> AsNestedSet.execute(Repo)
      
IO.inspect root_node
IO.inspect child_node
# root node, works fine, lft and rgt are calculated
%SomeApp.Api.Node{
  __meta__: #Ecto.Schema.Metadata<:loaded, "nodes">,
  emotion_id: 65,
  id: 96,
  inserted_at: ~N[2022-03-31 09:10:34],
  lft: 0,
  name: "root",
  parent_id: nil,
  rgt: 1,
  updated_at: ~N[2022-03-31 09:10:34]
}
# supposed to be a child of root node, but it's not
%SomeApp.Api.Node{
  __meta__: #Ecto.Schema.Metadata<:loaded, "nodes">,
  emotion_id: 65,
  id: 97,
  inserted_at: ~N[2022-03-31 09:10:34],
  lft: nil,
  parent_id: nil,
  rgt: nil,
  updated_at: ~N[2022-03-31 09:10:34]
}

Am I missing something? Seemingly two identical ways of creating an entity in the tree behave differently. If I create a child node as another root first and move it, it works, but creating it as a child right away does not seem to be working.

Elixir 1.13.2
as_nested_set 3.4.1
ecto 3.7.2
phoenix 1.6.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant