Bug fix for a regression in recent chnages

Bug fix for a regression I introduced accidentally in my recent changes whereby foreign key relations were not tracked. Was not covered by specs--have now added specs so it doesn't happen again.