stefankroes/ancestry

arrange_serializeable childrens are empty

exocode opened this issue · 4 comments

Sorry for making noise, may it's only my misunderstanding of the gem usage

How to serialize children. It looks quite obvious in the docs, but in my "real life" it's empty (see below)

https://github.com/stefankroes/ancestry#user-content-arrangement
It's the same code, I only added children_count to verify that children exist

Did I miss something?

>> Category.roots.arrange_serializable do |parent, children|
   {
     my_id: parent.id,
     my_children_count: parent.children_count,
     my_children: children
   }
 end

    Category Load (0.3ms)  SELECT "categories".* FROM "categories" WHERE "categories"."ancestry" IS NULL
=> [
{:my_id=>537, :my_children_count=>11, :my_children=>[]},
{:my_id=>166, :my_children_count=>8, :my_children=>[]},
{:my_id=>922, :my_children_count=>14, :my_children=>[]},
{:my_id=>222, :my_children_count=>19, :my_children=>[]},
{:my_id=>888, :my_children_count=>2, :my_children=>[]},
{:my_id=>772, :my_children_count=>2, :my_children=>[]},
{:my_id=>469, :my_children_count=>3, :my_children=>[]}]

Thank you very much in advance

Whatever I try, my children are ALWAYS empty. What can that be?

It is to pull out hair

root = Category.create(id: 1, name: "root") 
child1 = Category.create(id: 2, name: "child1", parent: root)
grandchild = Category.create(id: 3, name: "grandchild", parent: child1)

result:

Category.find(1).children.arrange_serializable

=> [
{"id"=>2, 
"name"=>"child1", 
"ancestry"=>"1", 
"ancestry_depth"=>1, 
"slug"=>"child1", 
"children_count"=>1, 
"children"=>[]} ### EMPTY
]

But the tree ist there:


Category.find(1).subtree

Category Load (0.4ms)  SELECT "categories".* FROM "categories" WHERE "categories"."id" = $1 LIMIT $2  [["id", 1], ["LIMIT", 1]]
  Category Load (0.2ms)  SELECT "categories".* FROM "categories" WHERE (("categories"."ancestry" LIKE '1/%' OR "categories"."ancestry" = '1') OR "categories"."id" = 1) /* loading for inspect */ LIMIT $1  [["LIMIT", 11]]
=> #

<ActiveRecord::Relation [
#<Category id: 3, name: "grandchild", created_at: "2021-04-07 22:48:05.702308000 +0000", updated_at: "2021-04-07 22:48:05.702308000 +0000", ancestry: "1/2", ancestry_depth: 2, gid: nil, slug: "grandchild", children_count: nil, products_count: 0, main_products_count: 0>, 
#<Category id: 1, name: "root", created_at: "2021-04-07 22:48:05.680101000 +0000", updated_at: "2021-04-07 22:48:05.705786000 +0000", ancestry: nil, ancestry_depth: 0, gid: nil, slug: "root", children_count: 1, products_count: 0, main_products_count: 0>, 
#<Category id: 2, name: "child1", created_at: "2021-04-07 22:48:05.692009000 +0000", updated_at: "2021-04-07 22:48:05.712200000 +0000", ancestry: "1", ancestry_depth: 1, gid: nil, slug: "child1", children_count: 1, products_count: 0, main_products_count: 0>
]>


Is there a way to modify https://github.com/stefankroes/ancestry/blob/remove_overalls/test/concerns/arrangement_test.rb#L130 to show what is going wrong?

The usage in the test is similar to what you have, but feels a little different

@exocode were you able to create a test that reproduces this on your system?
Did you end up finding out what was wrong in your system?

the arrangement test is working and I haven't gotten any feedback on this on.

If you are still having issues, please open another ticket.