feat(medusa-interfaces): Adds schema options to base model
This commit is contained in:
@@ -35,13 +35,30 @@ class BaseModel {
|
||||
return this.constructor.modelName
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the schema options defined in child class.
|
||||
* @return {object} the schema options
|
||||
*/
|
||||
getSchemaOptions() {
|
||||
if (!this.constructor.schemaOptions) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return this.constructor.schemaOptions
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* Creates a mongoose model based on schema and model name.
|
||||
* Creates a mongoose model based on schema, schema options and model name.
|
||||
* @return {Mongooose.Model} the mongoose model
|
||||
*/
|
||||
createMongooseModel_() {
|
||||
return mongoose.model(this.getModelName(), this.getSchema())
|
||||
const schema = this.getSchema()
|
||||
const options = this.getSchemaOptions()
|
||||
|
||||
const mongooseSchema = new mongoose.Schema(schema, options)
|
||||
|
||||
return mongoose.model(this.getModelName(), mongooseSchema)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user