Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot access to the Model<> on deleteOne pre hook #12622

Closed
vkarpov15 opened this issue Nov 1, 2022 Discussed in #12586 · 0 comments · Fixed by #12642
Closed

cannot access to the Model<> on deleteOne pre hook #12622

vkarpov15 opened this issue Nov 1, 2022 Discussed in #12586 · 0 comments · Fixed by #12642
Labels
typescript Types or Types-test related issue / Pull Request
Milestone

Comments

@vkarpov15
Copy link
Collaborator

Discussed in #12586

Originally posted by DocAmaroo October 24, 2022
Hi guys!

Before to open an issue, I wanted to ask if this was a default behavior.

I tried to create a pre hook with the deleteOne method and I couldn't access to the model of my class.

@Schema()
export class MyClass {
  @Prop()
  ...
}

export type MyClassDocument = SimulationDataset & Document;
export const MySchema = SchemaFactory.createForClass(MyClass);

MySchema.pre('deleteOne', function () {
  this.model; // TS2551: Property 'model' does not exist on type 'Document<unknown, any, SimulationDataset> & SimulationDataset & { _id: ObjectId; }'. Did you mean '$model'? 
});

Error received

TS2551: Property 'model' does not exist on type 'Document<unknown, any, SimulationDataset> & SimulationDataset & { _id: ObjectId; }'. Did you mean '$model'?

See screenshot

image

But this property is accessible from other method like deleteMany, findOneAndDelete etc…

Configuration

MongoDB shell version v5.0.13
Build Info: {
    "version": "5.0.13",
    "gitVersion": "cfb7690563a3144d3d1175b3a20c2ec81b662a8f",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Is this a normal behavior, or am I missing something from the documentation ?

Thank you in advance for your response.

@vkarpov15 vkarpov15 added the typescript Types or Types-test related issue / Pull Request label Nov 1, 2022
@vkarpov15 vkarpov15 added this to the 6.7.3 milestone Nov 1, 2022
lpizzinidev added a commit to lpizzinidev/mongoose that referenced this issue Nov 2, 2022
@vkarpov15 vkarpov15 modified the milestones: 6.7.3, 6.7.2 Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
typescript Types or Types-test related issue / Pull Request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant