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

Schema.loadClass overwrite methods from inherited class #8892

Closed
hasezoey opened this issue Apr 29, 2020 · 2 comments · Fixed by #8897
Closed

Schema.loadClass overwrite methods from inherited class #8892

hasezoey opened this issue Apr 29, 2020 · 2 comments · Fixed by #8897
Assignees

Comments

@hasezoey
Copy link
Collaborator

Do you want to request a feature or report a bug?
bug

What is the current behavior?
if an class extends another class and has the same names for something like an getter / setter, then the bottom-most class's getter / setter is used

If the current behavior is a bug, please provide the steps to reproduce.
(Typescript)

// NodeJS: 12.16.2
// MongoDB: 4.2-bionic (Docker)
import * as mongoose from "mongoose"; // mongoose@5.9.10

class C1 {
  public get hello() {
    return 1;
  }
}

class C2 extends C1 {
  public get hello() {
    return 2;
  }
}

(async () => {
  await mongoose.connect(`mongodb://localhost:27017/`, { useNewUrlParser: true, dbName: "mongooseLoadClassInheritance", useCreateIndex: true, useUnifiedTopology: true });

  const C1Schema = new mongoose.Schema({});
  C1Schema.loadClass(C1);
  const C1Model = mongoose.model("C1", C1Schema);
  console.log("C1Model", ((new C1Model()) as any).hello); // expected: "1", result: "1"

  const C2Schema = new mongoose.Schema({});
  C2Schema.loadClass(C2);
  const C2Model = mongoose.model("C2", C2Schema);
  console.log("C2Model", ((new C2Model()) as any).hello); // expected: "2", result: "1"

  await mongoose.disconnect();
})();

What is the expected behavior?
to use the top-most class's getter/setter-

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
mongoose: 5.9.10
typescript: 3.8.3
nodejs: 12.16.2

@vkarpov15
Copy link
Collaborator

Confirmed that this is already fixed, added a test in #8892

@hasezoey
Copy link
Collaborator Author

hasezoey commented Aug 8, 2021

Confirmed that this is already fixed, added a test in #8892

for anyone coming across this issue, i think it meant instead of 8892 to be #8897

also, this issue was fixed when #9975 got reported in 0f80ef8 (included in version 5.11.19)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants