merged whole_set_of and keys_to_instances_iter in BaseModel