Fixed capturing foreign keys on master inserts.

Added testing, discovered bug...