-
Notifications
You must be signed in to change notification settings - Fork 7
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
OGM save RelatedObjects - feature flag to keep relationships not in list of nodes #896
Labels
Comments
This is possible by adding a field to the --- venv/lib/python3.7/site-packages/py2neo/ogm/__init__.py 2021-05-10 15:52:20.237786016 -0400
+++ other/venv/lib/python3.7/site-packages/py2neo/ogm/__init__.py 2021-05-10 15:47:16.313949017 -0400
@@ -336,8 +337,10 @@
tx.merge(related_object)
# 2a. remove any relationships not in list of nodes
subject_id = self.node.identity
- tx.run("MATCH %s WHERE id(a) = $x AND NOT id(b) IN $y DELETE _" % self.__relationship_pattern,
- x=subject_id, y=[obj.__node__.identity for obj, _ in related_objects])
+ if not self.subject.__preserve_relationships__:
+ tx.run("MATCH %s WHERE id(a) = $x AND NOT id(b) IN $y DELETE _" % self.__relationship_pattern,
+ x=subject_id, y=[obj.__node__.identity for obj, _ in related_objects])
+
# 2b. merge all relationships
for related_object, properties in related_objects:
tx.run("MATCH (a) WHERE id(a) = $x MATCH (b) WHERE id(b) = $y "
@@ -424,6 +427,7 @@
__primarylabel__ = None
__primarykey__ = None
+ __preserve_relationships__ = False # False for existing behavior
__ogm = None
def __eq__(self, other): |
This sounds like a good feature request. I'll look into it. |
@technige any update? |
No, not had time to look into this yet. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
__db_push__
function inRelatedObjects
class will delete any existing relationships for a node that are not represented by the current set of nodes on push. This creates orphan nodes when adding relations via merge to an existing node with existing relationships.I've commented out line
340
/ step 2a in this function and the relationships are preserved. Would it be possible to make this a feature flag? Also, are there any problems that could arise from doing this?The text was updated successfully, but these errors were encountered: