New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete nodes from leafs up to root #635
Conversation
This is my current strategy:
It's slow because it steps through the tree deleting one at a time. I probably cut some corners there as I determined that some checks weren't relevant in my situation. |
|
d2d73b5
to
d2d0eb8
Compare
re 2: what ever works and is the easiest to support I wanted to make sure in #632 that I handle most of the use cases around orphan_strategies I'm trying to go more towards the dynamic route. |
Haha, That code in ActsAsList! That was done by a contractor I had in the past, it drives me nuts but what's done is done :D Personally I don't like the way it abstracts the configuration process away into many files. It's difficult to grok, but I get why one would want to clean it up that way. Ideally if you cover off most overridden orphan strategies then there won't be a need to override them anymore. Perhaps in #632 you could adjust the code to allow one to use one of your built-in strategies or to nominate one of their own via a symbol that calls a method on the model. Essentially you'd have a constant with a hash of built in orphan strategy names as keys with the values being the method names, then you'd just check if the orphan strategy is one of those set a The main problem with that is that a typo would lead to the code trying to call a non-existent method on destroy which could be confusing. You could instead have two config settings, orphan_stratgegy: (one of the built in ones, or :custom), then custom_orphan_strategy_method: (the symbol of the method, and this gets enforced if the strategy is :custom). Just some thoughts an away :D |
Thanks, good point. I will take that into account I'm glad your ideas around I'm concerned around the current code defining a method inline. If you added your concern before running Thanks again for the great input. Ping any time you need help with |
Thanks @kbrock, will do! :) I actually had a stab at writing my own positioning Concern and it's working quite well. It works more like acts_as_list but has much more focus on correct and failproof reordering within transactions so that a consistent state is maintained without gaps between items. For now I'm completely flat out so can only focus on reviewing other's PR's.
|
d2d0eb8
to
ade82ed
Compare
When destroying dependents, start with the furthest down leafs and work your way up to the current node stefankroes#90
ade82ed
to
d00654a
Compare
update:
|
Just wondering if this needs a test case to confirm that it fixes the problem? Hard to re-create though. |
When we don't specify the order, it most likely would bring back the data in id order, depending upon the index that the database uses. And we typically create parents then children. So the parents have an id lower / earlier in the indexes (and definitely in the ancestry indexes), so it was probably always deleting from root to child. Not sure how to write a red-green tests here. |
I think an |
When destroying dependents, start with the furthest down leafs and work your way up to the current node
#90
@miguelgraz @brendon You still using ancestry? Do you remember if this is the solution you used?
This seems like a good change, but want some feedback in terms of what unintended side effects will be introduced.
Current destroy does not specify an order. The database will tend towards insert order, and that tends to be parent down to children.