GithubHelp home page GithubHelp logo

Comments (7)

WillsonHaw avatar WillsonHaw commented on May 13, 2024 4

The workaround I've been using is to use an object with a name property as the class name as the ref/itemsRef:

class Chapter extends Typegoose {
    @prop({ ref: { name: 'Series' } }) public series: Ref<Series>;
}

class Series extends Typegoose {
    @arrayProp({ itemsRef: { name: 'Chapter' } }) public chapters: Ref<Chapter[]>;
}

Seems to work so far for me, but probably not something that'll work long term.

from typegoose.

pgsfredda avatar pgsfredda commented on May 13, 2024 1

Hi @WillsonHaw ,

I tested your solution: it works perfectly with 'populate' method.

I think this is not a workaround. This is using the metadata.

Thank you!

from typegoose.

szokodiakos avatar szokodiakos commented on May 13, 2024

Hello. Yes I believe at this time, circular schema definitions are not supported, haven't tested it myself though but judging by your example that is the case.

I will keep an eye on this when developing Typegoose (also all PRs are appreciated).

from typegoose.

pgsfredda avatar pgsfredda commented on May 13, 2024

EDIT: 10/oct/2017:
Maybe I found the solution but I'm still testing that.
I'm using Angular forwardRef function.
It seems it works.

import { prop, staticMethod, instanceMethod, Typegoose, ModelType, InstanceType, Ref } from 'typegoose';

import { forwardRef } from 'forwardref'
import { User } from './user.model';

export class AdminName {
    @prop() first: string;
    @prop() last: string;
};

export class Admin extends Typegoose {
    @prop() name?: AdminName;
    @prop({ ref: forwardRef(() => User) }) user?: Ref<User>;
}

export const AdminModel = new Admin().getModelForClass(Admin);

from typegoose.

pgsfredda avatar pgsfredda commented on May 13, 2024

Great! Thank you.
It transpilles. ;-)

Why do you think this solution is not good in the long term?
The 'name' property for the 'ref' field works for the mongoose 'populate' method?

from typegoose.

WillsonHaw avatar WillsonHaw commented on May 13, 2024

If that metadata changes, then it can be an issue. Not likely, but just keep that in mind. Glad it worked out for you though!

from typegoose.

hasezoey avatar hasezoey commented on May 13, 2024

@Ben305 this can be closed as "not an issue with typegoose" - limitation of javascript

if someone has this error, please look at https://typegoose.github.io/typegoose/guides/advanced/reference-other-classes/

from typegoose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.