Skip to content

no nodes getting a depth of more than 0 #144

Closed
@birarda

Description

@birarda

I have a model Place that has a column pointee_id. I use pointee for a polymorphic association, but would like to use closure_tree to get ancestry for the place up to the root. pointee_id typically refers to a place, which allows for the tree structure. Eventually it will point to a different model, and this becomes my root node. I've written a has_many through association to get that root model (since I don't expect closure tree to be able to grab this for me, it's checking the Place model).

The issue I'm having is that after Place.rebuild! or a place update to point to another place, doesn't seem to add the hierarchy properly to the place_hierarchies database. It adds the record for each place that points to itself #<PlaceHierarchy ancestor_id: "7315a306-8c46-449e-91c9-6ce690d050f3", descendant_id: "7315a306-8c46-449e-91c9-6ce690d050f3", generations: 0> but nothing else. All of my PlaceHierarchy records have generations = 0.

Some of the closure tree methods work - I can find the parent and the children properly - but since all records in place_hierarchies have generations = 0, I can't find any ancestors for the node.

My model has the following:

class Place < ActiveRecord::Base
  has_closure_tree parent_column_name: 'pointee_id' 

I ran the closure tree migration for the Place model.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions