-
Notifications
You must be signed in to change notification settings - Fork 467
Open
Description
Greetings,
The ancestry gem currently assumes that the parent-child relationship is managed using the primary key.
However, there are certain cases where a different unique column needs to be used to manage the relationship when we use other columns as a identifier.
This is how it would behave;
class Category
has_ancestry ancestry_identifier_column: :another_identifier_column
end
root = Category.create!(another_identifier_column: 100)
node = Category.new(another_identifier_column: 200)
node.ancestor_ids = [root.another_identifier_column]
node.save!
node.ancestry
#=> 100
Some gems allow customizing the column used for managing parent-child relationships. For instance, the awesome_nested_set gem provides a primary_column
option that enables users to specify which column should be used as the parent reference (parent_id).
I am currently working on a PR to add this feature to ancestry, as I need it for my product. I’d be happy to submit it if you find this approach acceptable.
Metadata
Metadata
Assignees
Labels
No labels