fix bad behaviour for foreign key