Convert foreign key in params to where clause

This fixes issue #240