profile
viewpoint

Ask questionsNaming collision between attribute 'id' and association 'id' on model SpaceModel. To remedy this, change either foreignKey or as in your association definition

Versions

  • sequelize: 5.8.8
  • sequelize-typescript: 0.6.11
  • typescript: 3.5.2

questions

this is my ComponentModel

export class ComponentModel extends Model<ComponentModel> {
  // validate if need
  @BelongsToMany(() => SpaceModel, () => SpaceComponentModel,  'component_id')
  @Column({
    primaryKey: true,
  })
  public id: number;

  @Column({
    field: 'p_componnet_id',
  })
  public pComponentId: number;
}

this is my SpaceModel

export class SpaceModel extends Model<SpaceModel> {
  // validate if need
  @BelongsToMany(() => ComponentModel, () => SpaceComponentModel, 'space_id')
  @Column({
    type: BIGINT(20),
    primaryKey: true,
  })
  public id: number;

}

this is my SpaceComponentModel

export class SpaceComponentModel extends Model<SpaceComponentModel> {
  @Column({
    primaryKey: true,
  })
  public mpId: number;

  @ForeignKey(() => SpaceModel)
  @Column({
    field: 'space_id',
  })
  public fkSpaceId: number;

  @ForeignKey(() => ComponentModel)
  @Column({
    field: 'componnet_id',
  })
  public fkComponentId: number;
}

Actual behavior: image

questions I have set the foreign key in BelongsToMany, why id is collision?

RobinBuschmann/sequelize-typescript

Answer questions RobinBuschmann

Closing this due to inactivity

useful!
source:https://uonfu.com/
Github User Rank List