zakodium / adonis-mongodb

MongoDB provider for AdonisJS 5
https://zakodium.github.io/adonis-mongodb/
Other
63 stars 12 forks source link

How to import the base model #100

Closed pilot22 closed 3 years ago

pilot22 commented 3 years ago

Hello. I don't understand how to import and extend the BaseModel interface

Right now im getting an error while doing this:

import { Model } from '@ioc:Zakodium/Mongodb/Model'

export default class User extends Model {
  public static collectionName = 'users'

  public name: number
}

E_IOC_LOOKUP_FAILED: Cannot resolve "Zakodium/Mongodb/Model" namespace from the IoC Container"

import { MongodbModel } from '@ioc:Zakodium/Mongodb/Odm'

export default class User extends MongodbModel {
  public static collectionName = 'users'

  public name: number
}

Class extends value undefined is not a constructor or null

Help please

pilot22 commented 3 years ago

Resolved by:

import { BaseModel } from '@ioc:Zakodium/Mongodb/Odm'

export default class User extends BaseModel {
  public static collectionName = 'users'

  public name: number
}
stropitek commented 3 years ago

Note that you don't have to set a collectionName, it will be generated from the constructor's name.