0

I have two entities A & B and a many-many relation entity AB. How to implement the following sequence in the most appropriate react way without terminal actions

  1. Fetch AB by idAB
  2. Fetch A by AB.idA, update & save A
  3. Fetch B by Ab.idB, update & save B
  4. Delete AB by idAB
  5. Return the updated A Thank you in advance, Sergey
ysa
  • 141
  • 1
  • 7

1 Answers1

0

It seems the best way is as follows

        abRepository.findById(abId)
                .flatMap(ab->abRepository.deleteById(abId).thenReturn(ab))
                .flatMap(ab-> bRepository.findById(ab.getBId())
                        .flatMap(b->bRepository.save(b.update(ab)).thenReturn(ab)))
                .flatMap(ab-> aRepository.findById(ab.getAId())
                        .flatMap(a->aRepository.save(a.update(ab))))

where (a,b,ab)repositories extend ReactiveCrudRepository.

ysa
  • 141
  • 1
  • 7