How are people dealing with circular dependencies?
See original GitHub issueI have models define in separate files that reference each other. Is there a way to deal with circular dep issues without combining the models into one file?
import { Table, Column, Model, HasOne } from 'sequelize-typescript';
import User from './User.model';
@Table({ timestamps: true })
export default class Post extends Model {
@HasOne(() => User)
author!: User;
@Column
title!: string;
@Column
content!: string;
}
import { Table, Column, Model, HasMany } from 'sequelize-typescript';
import Post from './Post.model';
@Table({ timestamps: true })
export default class User extends Model {
@Column
name!: string;
@HasMany(() => Post)
posts!: Post[];
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
How to Eliminate Circular Dependencies from Your JavaScript ...
Circular dependencies are usually an indication of bad code design, and they should be refactored and removed if at all possible.
Read more >How to solve circular dependency?
Technically, you can resolve any cyclic dependency by using interfaces, as shown in the other answers. However, I recommend to rethink your ...
Read more >Circular Dependencies in Spring - Baeldung
A quick writeup on dealing with circular dependencies in Spring: how they occur and several ways to work around them.
Read more >How to fix nasty circular dependency issues once and for all in ...
Although there are many strategies and best practices on how to avoid circular dependencies. There is very little on how to fix them...
Read more >Circular dependency - Wikipedia
In software engineering, a circular dependency is a relation between two or more modules ... (those that use reference counting) from deallocating unused...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
IMHO the code below should be adjusted to help avoid the need for recursive imports:
So that
becomes
@RobinBuschmann I took an initial stab at this. Would be great if someone could give me some feedback on whether this is a good idea or not: https://github.com/mschipperheyn/sequelize-typescript/commit/89bbef67201394d2fe4d832a8e2e8c4565e67bb7