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
Implement deferred save/deletion (autosave/mark_for_destruction) functionality #1401
Comments
@brianewell, is your goal to mark several things for deletion and then send them all to the database as part of one http request? Because you may be able to accomplish this using neo4j-core's
|
Good callout @thefliik ! One thing to note is that the But if that's not it, an attempt to add the feature would definitely be welcome! I would suggest laying out an example(s) in this issue so that we can discuss it. At some point it would be great to be able to have the ability to batch create / update objects similar to the Also be aware that there is the |
@thefliik
Ideally, I'd like to create, update or mark for destruction several nodes/relations associated with some primary node and have all of those changes included within the same neo4j transaction block (making them atomic, assuming I understand neo4j transactions). My specific use case has a single form manipulating multiple nodes and relationships (I'm making heavy use of
Thanks for the pointer, I'll definitely check that approach out first. This post was mainly intended as an inquiry into if the feature actually already existed (and I just couldn't find it) or if it had been attempted before and for some reason didn't persist.
Sure thing! What I envision is something similar to ActiveRecord's autosave association functionality. Specifically "a module that takes care of automatically saving associated records when their parent is saved. In addition to saving, it also destroys any associated records that were marked for destruction." The use case would be pretty much the same as the use case outlined in the ActiveRecord module. I'll provide an example based on the ActiveRecord version linked above: One-to-one Example
Saving changes to the parent and its associated model can now be performed automatically and atomically:
Destroying an associated model, as part of the parent's save action, is as simple as marking it for destruction:
Note that the author is not yet removed from the database:
Until the post is saved:
One-to-many ExampleThe default behavior of ActiveRecord when
While this is default behavior for ActiveRecord, it's not default neo4j.rb behavior, and I'm reluctant to change existing behavior. I also question the consistency of this decision on the part of ActiveRecord (why is the save operation for one object explicitly saving another object without my input?) Regardless we can certainly have a discussion about it. What I would like to see here is an autosave option which will automatically create any new nodes and relationships, modify any updated nodes and relationships, and delete any marked nodes and relationships by following any
Additionally, the association proxy could be extended with
Using
Additionally
As of neo4j.rb 8.0.18 this fails to properly commit unless asset and category have been explicitly committed beforehand. This should be enough to spark conversation. Please let me know your thoughts. |
It's been quite a while but I seem to remember doing a little research and coming away thinking that |
You can already / easily wrap multiple queries inside one transaction block using
This will make everything wrapped inside those transaction blocks roll back on a failure. Of note though, if any transaction fails within a group of nested transactions, all of the transactions in that nesting will fail (basically, the failure bubbles up). Neo4j supports a lite version of ActiveRecord's |
As @subvertallchris we'd need an association cache, but I'm pretty sure that we have that now in the Regarding the default behavior of In short, I think it would be wonderful to have |
@thefliik
I'm sorry for not communicating this more clearly earlier. I would like behavior that automatically saves associated records when a parent record is saved, and allows records to be flagged for deletion and deleted when some a parent record is saved (or potentially when deleted). I was getting wrapped up in the details of wanting that save to also occur within a single transaction, and while that's still critical and true, it's a much smaller part of the bigger picture. As of this morning, I was saving associated records using a custom
While this definitely addresses my concerns about atomic transactions (thank you for that), I'm still finding that management logic for this ('do pre-save stuff' and 'save other objects') is taking up more space in my model than I'd like it to, especially compared to the business logic is. I'm also recognizing that I've been tending to repeat my object management code in different models, violating DRY. I will look closer into |
I'm curious if there's reason that deferred save/deletion functionality hasn't been implemented in neo4jrb (or if it has and I just couldn't find it). As I've been limping around this limitation in one of my projects, I'd be willing to attempt implementing it, I'm just doing some cursory reconnaissance before I dig deeper into the code.
The text was updated successfully, but these errors were encountered: