祖先从父母身份重建

问题描述:

我有类树型结构。在我的数据库中,我有大约1500条记录。 当我尝试使用命令“Category.build_ancestry_from_parent_ids!”从父ID重建祖先时结果我得到零。祖先从父母身份重建

这里是结果。

1.9.2p290:006 Category.build_ancestry_from_parent_ids! 类别加载(1.8ms)SELECT“categories”。* FROM“categories”WHERE“categories”。“parent_id”IS NULL AND(“categories”。“id”> = 0)ORDER BY“categories”。“id”ASC LIMIT 1000 =>无

我从https://github.com/stefankroes/ancestry以下的方向,但似乎我失去了一些东西。

以前是否有同样的问题?

我找到了解决方案。我不得不把参数,以使其正常工作。

Category.build_ancestry_from_parent_ids!(parent_id =0 , ancestry =0) 

很可能把parent_id =1,然后过渡将跳过属于根级别的所有类别。