Skip to content

Incoming relationships must be set on both sides to actually persist #2264

Closed
@jposthauer

Description

@jposthauer

With the given setup, the test only passes if I have both actor.movies.add(movie) AND movie.actors.add(actor). I would expect that actor.movies.add(movie) would be sufficient.

@Node
public class Actor {
    @Relationship(type = "ACTED_IN")
    private List<Movie> movies;
}

@Node
public class Movie {
     @Relationship(type = "ACTED_IN", direction = Relationship.Direction.INCOMING)
     private List<Actor> actors = new ArrayList<>();
}


@Query("MATCH (actor:Actor {id: $actorId}) "
    + "OPTIONAL MATCH (actor)-[acted_in:ACTED_IN]->(movie:Movie)"
    + "RETURN actor, COLLECT(acted_in), COLLECT(movie);")
Optional<Actor> findByIdWithMovies(String actorId);


@Test
fun findByIdWithMovies() {
    val actor = Actor()
    val movie = Movie()

    actor.movies.add(movie)
    movie.actors.add(actor)
    actorRepository.save(actor)

    val consumed = actorRepository.findByIdWithMovies(actor.id).get()
    assertThat(consumed.movies).isNotEmpty
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions