Skip to content
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

Feature Request: Add option to just save a single node #2762

Open
Dimibe opened this issue Jul 8, 2023 · 0 comments
Open

Feature Request: Add option to just save a single node #2762

Dimibe opened this issue Jul 8, 2023 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@Dimibe
Copy link
Contributor

Dimibe commented Jul 8, 2023

currently the neo4jTemplate.save method saves the whole sub graph provided. This makes it hard to just create or update a single node which has relations to other nodes.

Request:
Adding a method e.g. neo4jTemplate.saveJust(node) which will create/update just the provided node and the relations to other nodes. Instead of also creating related nodes it will expect the related nodes to already exist and fail if this it not the case.
So basically the same logic as the current save method explained in the docs: Appendix -> Query Creation but with a modified step 3 and without step 5.

Current solution:

My current solution is to use projections for the node classes I want to save. E.g. I have a User-Node and Post-Node and when adding a new Post I want to link it with the user who posted the post:

public class User {
  
  @Id @GeneratedValue
  String id;
  String name;
  String email;

  @Relationship(type = "FOLLOWER" direction = Relationship.Direction.INCOMMING)
  Set<User> follower;

}
public class Post {
  
  @Id @GeneratedValue
  String id;
  String title;
  String description;

  @Relationship(type = "POSTED_BY" direction = Relationship.Direction.OUTGOING)
  User user;
}

My projections look like this:

public interface PostProjection extends IdProjection {
  String getTitle();
  String getDescription();
  String getImageUrl();
  IdProjection getUser();
}

public interface IdProjection {
  String getId();
}

When using neo4jTemplate.saveAs(node, PostProjection.class) I get the expected result that just the post and relation to the user is created without the user being modified.

Motivation:

I think that creating/updating a single node is a general use case and with the current solution I have to create projection interface for almost every node-class which exactly following the same schema:
Every projection interface contains getter for all properties, plus getters with IdProjection for all relationships.

From my point of view this is very much boilerplate code and makes the project harder to maintain as adding new fields requires updating the node class and the projection class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants