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

Error: Alias cannot be inferred: "model" has multiple relations with "another-model" #1385

Closed
1 of 2 tasks
zignis opened this issue Aug 8, 2022 · 1 comment
Closed
1 of 2 tasks

Comments

@zignis
Copy link

zignis commented Aug 8, 2022

Issue

Follower model:

  ...
  @ForeignKey(() => User)
  @AllowNull(false)
  @Column({
    type: DataType.BIGINT,
  })
  public followee_id: string;

  @ForeignKey(() => User)
  @AllowNull(false)
  @Column({
    type: DataType.BIGINT,
  })
  public follower_id: string;

  @BelongsTo(() => User, 'followee_id')
  public followee: User;

  @BelongsTo(() => User, 'follower_id')
  public follower: User;
  ...

User model:

  ...
    @HasMany(() => Relation, {
    as: 'followers',
    foreignKey: 'followee_id',
    hooks: true,
    onDelete: 'CASCADE',
  })
  public followers: Relation[];

  @HasMany(() => Relation, {
    as: 'followees',
    foreignKey: 'follower_id',
    hooks: true,
    onDelete: 'CASCADE',
  })
  public followees: Relation[];
  ...

Error:

Error: Alias cannot be inferred: "Relation" has multiple relations with "User"

Versions

  • sequelize: 6.21.3
  • sequelize-typescript: 2.1.3
  • typescript: 4.7

Issue type

  • bug report
  • feature request
@zignis
Copy link
Author

zignis commented Aug 8, 2022

Turned out to be my mistake, forgot to add alias in the default scope.

@zignis zignis closed this as completed Aug 8, 2022
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

No branches or pull requests

1 participant