zakodium / adonis-mongodb

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

_id default type should be ObjectId instead unknown #118

Open maasencioh opened 3 years ago

maasencioh commented 3 years ago

https://github.com/zakodium/adonis-mongodb/blob/638a5ec3054c92aec75fc144eb7ca331ee567b50/adonis-typings/odm.ts#L365

targos commented 3 years ago

This is not the default type, as there is no way to have a "default" for exported values. Try to put ObjectId here, it will break the package.

maasencioh commented 3 years ago

As far as I understand when you do something like this

export default class Test extends BaseModel {
  @field()
  public foo: string;
}

in the database will use _id as ObjectId, then I think that it should made sense that change

targos commented 3 years ago

Feel free to try it, but this change didn't work when I implemented the typings. I agree that unknown is not the best thing here, but I haven't found an alternative yet that allows to change the type to something else. (for example number or string). In our models, we always add the type for _id:

class SomeModel extends BaseModel {
  @field()
  override _id: ObjectId;
}