Skip to content
This repository has been archived by the owner on Jun 29, 2021. It is now read-only.

Support inheritance from abstractModel (old: staticMethod not giving model as this) #28

Closed
cryptiklemur opened this issue Aug 27, 2017 · 6 comments

Comments

@cryptiklemur
Copy link

cryptiklemur commented Aug 27, 2017

Using the following code:

export default abstract class AbstractModel extends Typegoose {
    @staticMethod
    public static findByIdentifier(this: ModelType<AbstractModel>, identifier: Long) {
        return new Promise((resolve, reject) => {
            console.log(this);
            this.findOne({identifier}).then(resolve).catch(reject);
        });
    }

    @prop({required: true, index: true, unique: true})
    public identifier: string;
}

this is always an instance of the model, instead of the model type, so i can't call findOne.

Feel like im missing something...

@szokodiakos
Copy link
Owner

Hello I think you haven't included some other Models' code. Can you please extend your example? Right now its hard to tell what is wrong.

@cryptiklemur
Copy link
Author

cryptiklemur commented Aug 27, 2017

Theres really not much to the other models

import AbstractModel from "./AbstractModel"

export default class User extends AbstractModel {
}

let user: User = await UserModel.findOneByIdentifier('some identifier here');

@cryptiklemur
Copy link
Author

I might be missing something, but it actually seems like inheritance is not supported

@vinczedani
Copy link
Collaborator

Hi @aequasi
Sorry for the late response. The current version of typegoose is not written with inheritance support in mind. I mark this issue with enhancement instead of question.
Thanks, Daniel

@vinczedani vinczedani changed the title staticMethod not giving model as this Support inheritance from abstractModel (old: staticMethod not giving model as this) Sep 20, 2017
@buzzyboy
Copy link

buzzyboy commented Mar 4, 2019

Has there been any update to creating this enhancement?

hasezoey referenced this issue in typegoose/typegoose Aug 7, 2019
- use schema.loadClass() instead of self-handling it
- breaking many things
- adding docs for virtual-populate
- deprecating method decorators
- deprecating setModelForClass
- moving _buildSchema to its own file
- adding error tests
- adding more errors
- rebuilding how schema generation works
- adding more docs to VirtualOptions
- adding "count" to VirtualOptions

fixes szokodiakos#48
fixes szokodiakos#28
fixes szokodiakos#246
fixes szokodiakos#182
@hasezoey hasezoey mentioned this issue Aug 7, 2019
14 tasks
@hasezoey
Copy link
Contributor

hasezoey commented Sep 10, 2019

this should work in v6.0.0

@Ben305 this can be closed

@Ben305 Ben305 closed this as completed Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants