Similar to #7141 - but #7141 didn't cover the fact that the issue also affected many-to-many relationships.
The fix provided in #7146 works for the one-to-many relationships, so I am opening this issue (with PR to follow shortly) to apply the same fix for many-to-many