Model::doSelectOne, fix foreign key bug and some extra cleanup.