sequelize-typescript icon indicating copy to clipboard operation
sequelize-typescript copied to clipboard

Association Error

Open keyduq opened this issue 8 years ago • 1 comments

I have this

@Table({
  tableName: "peso_productos"
})
export class PesoProducto extends Model<PesoProducto> {
  @ForeignKey(() => Vendedor)
  @Column
  vendedor_id: number;

  @BelongsTo(() => Vendedor, "vendedor_id")
  vendedor: Vendedor;
}

Vendedor side:

  @Table({
    tableName: "vendedores"
  })
  export class Vendedor extends Model<Vendedor> {
    @HasMany(() => PesoProducto)
    pesoProductos: PesoProducto[];
  }

And just initializing sequelize throws this error

SequelizeAssociationError: You have used the alias vendedor in two separate associations. Aliased associations must have unique aliases.

What I'm doing wrong?

keyduq avatar Aug 06 '18 21:08 keyduq

I just figured out what was happening, I was initializing sequelize twice. You can close this issue guys and btw great library 👍

keyduq avatar Aug 06 '18 23:08 keyduq