I want to model following scenario: User (node) can have multiple posts (node) and Users can follow each other
Here's my spring boot model
@Node("User")
data class NeoUser(
@Id
val id: Long,
val username: String,
val fullName: String?,
val isPrivate: Boolean,
val isVerified: Boolean,
val profilePicUrl: String?,
@Relationship(type = "IS_FOLLOWING")
val friendships: Set<Friendship> = setOf(),
)
@RelationshipProperties()
data class Friendship(
@Id
@GeneratedValue
val id: Long? = null,
@TargetNode
val targetNode: NeoUser
)
@Node("Post")
data class NeoPost(
@Id
val id: Long,
val mediaType: MediaType,
val createdAt: Instant,
val expireAt: Instant,
val caption: String?,
val url: String,
@Relationship(type = "CREATED_BY", direction = Relationship.Direction.INCOMING)
val user: NeoUser
)
If i create post for user A, it works fine. However, if user A follows user B, post of user A is also following user B like below image. What am i doing wrong here?
Here's my query if required
MERGE (n:`User` {id: $__id__}) SET n = $__properties__ RETURN id(n)
Instances of class NeoUser with an assigned id will always be treated as new without version property!
MERGE (n:`User` {id: $__id__}) SET n = $__properties__ RETURN id(n)
MATCH (startNode) WHERE startNode.id = $fromId MATCH (endNode) WHERE id(endNode) = 3 MERGE (startNode)-[relProps:`IS_FOLLOWING`]->(endNode) SET relProps = $__properties__