[1.5.x] Fixed #17541 -- Fixed non-saved/nullable fk querying

Backpatch of 55da775ce1bfba20db33b56c29957faa63917980