attached a test case to reproduce the issue. Also a fix patch is provided for review.
The issue seems to be happening when fk is not desired and you have a parent/children (one-to-many) relationship with a composite key.