Allow ancestry to define a primary ancestry key - #747
Conversation
2c0362a to
3eb79fa
Compare
|
@a5-stable does this look like it would meet your needs? I'm trying to see if there is a way to patch this in or changes I can make in core so it is easier to patch. Have gotten this to be less invasive, but it sure goes everywhere. I was hoping that I could localize the changes just to the builder. Haven't gotten there yet and a little stuck. |
|
@kbrock Hi, thanks for creating the PR! I tried running our product with this branch. |
Introduce primary_ancestry_key class variable and ancestry_id instance method as the indirection point for which column values are stored in ancestry paths. Defaults to :id. On Rails 7.2+, auto-detects from primary_key. On older Rails, must be passed explicitly via has_ancestry primary_key: :code. Replaces bare id/node.id with ancestry_id/node.ancestry_id throughout static modules (instance_methods.rb, class_methods.rb) and builder. Replaces scope.primary_key with scope.primary_ancestry_key for record lookups by ancestry values. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
3eb79fa to
97705f1
Compare
OverviewI feel I am missing something. I don't understand how this code can work without a primary id. The existing STI support requires My concern is I don't want to introduce a lot more complexity than I will support, and others will have to debug if I'm not sure it will benefit you. Please help me understand how you associate 2 classes together and how the controller tells the model (and database) which record to return when you request RequestDo you have a simple example of a code base?
What I hope to gainI want to look at the plugin/gem's use of default scopes or how the date is determined. I want to see how you pass the data to the database so I can ensure the way Ancestry turns off scopes does not affect you. Also, it seems like all records are read-only. Not sure how ancestry would handle this. Thank you for your assistance. |
Description
Not sure if I want to commit, but putting this out there.
Many of the concepts are good. But not as readable as I'd like.
A lot of change, so this will get stale quickly.
Fixes #698
This allows ancestry to have
a/b/c/but the primary keys be1,2,3Before
After
Type of Change
Checklist
bundle exec rake test)How Has This Been Tested?