adonis-mongodb icon indicating copy to clipboard operation
adonis-mongodb copied to clipboard

_id default type should be ObjectId instead unknown

Open maasencioh opened this issue 2 years ago • 3 comments

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

maasencioh avatar Oct 11 '21 08:10 maasencioh

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.

targos avatar Oct 11 '21 08:10 targos

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

maasencioh avatar Oct 11 '21 08:10 maasencioh

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;
}

targos avatar Oct 11 '21 09:10 targos