Limiting Depth Problem
rctneil opened this issue · 2 comments
Hello,
We are successfully using Ancestry to output a nested <ul>
of people. We have enabled depth caching and tried to limit the depth to 5 levels, but it is still outputting all people. When we try to rebuild_depth_cache
the depth_cache column mostly seems to set people to 1. Is this correct?
My Person
model is:
class Person < ApplicationRecord
has_many :spouses, foreign_key: "marriage_person_id"
has_ancestry cache_depth: true
scope :people, -> { where(type: 'Person') }
scope :spouses, -> { where(type: 'Spouse') }
and the place where I am grabbing the tree of people:
@tree = Person.people.to_depth(5).order('birthdate ASC').arrange
Any suggestions?
Thanks,
Neil
Hello @rctneil
You should notice depths with many values. Have you verified that grandchildren only have a value of 1?
I'm curious the values for the spouse. Do spouses have parents? I'm guessing
Can you put together a ruby test with 5 people so I can see what is happening here?
Hello @rctneil
You should notice depths with many values. Have you verified that grandchildren only have a value of 1?
I'm curious the values for the spouse. Do spouses have parents? I'm guessing
Can you put together a ruby test with 5 people so I can see what is happening here?
Thanks for your reply. It appears that, the ancestry column had not been populated correctly when converting from a pure integer based parent_id column. A little big of finagling around with it has populated it correctly now and the depth column also works perfectly now. I was having weird issues when calling .has_children? on a node and getting false when there were definitely children. All fixed now.
Appreciate the reply though!
Neil