Apply fields to model.fields and store primary keys to model.primary list