bwgjoseph / mongoose-vs-ottoman

feature comparison between mongoose and ottoman
0 stars 1 forks source link

allow to grab `ModelMetadata` from `ModelTypes` #88

Open bwgjoseph opened 3 years ago

bwgjoseph commented 3 years ago

Hi,

Is there any way to grab the ModelMetadata from ModelTypes? Otherwise, is there any existing way to grab it?

My use case is to be able to infer the idKey from the Model

const modelName = 'posts';
const modelOptions: ModelOptions = {
  idKey: 'customId',
  scopeName: 'demopostscope',
  collectionName: 'demopostcollection',
};

const schema = new ottoman.Schema({
  text: { type: String, required: true },
});

const postModel = ottoman.getModel(modelName) || ottoman.model(modelName, schema, modelOptions);

I want to do things like

console.log(postModel.getModelMetadata().idKey) // customId
console.log(postModel.getModelMetadata().collectionName) // demopostcollection

If there isn't any existing way to do this, is it possible to expose it?

Thanks!