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

Fix circular dependency throws error #179

Merged
merged 3 commits into from
Mar 18, 2019

Conversation

labibramadhan
Copy link
Contributor

@labibramadhan labibramadhan commented Jan 5, 2019

Fix circular dependency throws maximum call stack size exceeded

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #136 #175

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Fix circular dependency throws maximum call stack size exceeded
@LukvonStrom
Copy link

This patch seems valid and solves the recursion issue. Why not merge it @kamilmysliwiec ?

@Hless
Copy link
Contributor

Hless commented Feb 20, 2019

labibramadhan#1

Created pull request on source branch for additional fix. It fixes some typescript compilation errors and also includes fixes for Circular deps between different models (#63), by using a function to resolve the external model, e.g:

// user.entity.ts
// AccessToken will be 'undefined' in runtime,
// because User and AccessToken depend on each other 
@import { AccessToken } from "./acces-token.enitity';
class User {
    ...
    
    @ApiModelProperty({ 
       // Using function instead of object resolves the cyclic depency issues, 
       // since the AccesToken class will be resolved when the decorator runs
        type: type => AccessToken ,  
        isArray: true 
     })
    @OneToMany(type => AccessToken, accessTokens => accessTokens.user)
    accessTokens:AccessToken[]
}

---
// access-token.entity.ts

@import { User } from "./user.entity";
class AccessToken {
    ...
    @ApiModelProperty({
        type: type => User,
     }) 
     @ManyToOne(type => User, user => user.accesTokens)
     user:User
}

Fixing ts syntax compile errors and added fix for resolving external …
@kamilmysliwiec kamilmysliwiec merged commit 0e6c6c0 into nestjs:master Mar 18, 2019
@kamilmysliwiec
Copy link
Member

Thanks!

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants