Fix #50, correctly detect the type of pk field and related fields