Skip to content

Edit Creates New Records Instead of Updating #10

@noahsettersten

Description

@noahsettersten

Hello,

We've encountered an issue where editing any record in AdminBro doesn't update the existing record, but actually inserts a new record in the database. So when we edit an item, we duplicate it with the same data (and a new generated ID primary key) instead of editing the existing item. This happens on any of our TypeORM entities, and it still occurs even with the simplified version I've posted below.

Here is a video demonstrating the issue: https://share.getcloudapp.com/kpuYod9O

No error is printed in the console, and AdminBro displays success in saving the record. I'm using a forked version of admin-bro-typeorm to avoid the problem in issue #5.

To rule out any issue with our versions of AdminBro or our configuration, I set up a basic Sequelize model for this same table and used the AdminBro Sequelize adapter. The issue does not happen there and is only specific to the TypeORM adapter.

Versions Used

  1. admin-bro: 1.6.6
  2. admin-bro-expressjs: 0.4.0
  3. admin-bro-typeorm: Forked version of 1.6-alpha.8 (https://github.com/headwayio/admin-bro-typeorm)
  4. typeorm: 0.2.22

We're running on Postgres 10 in Docker.

AdminBro Options

import { Database, Resource } from 'admin-bro-typeorm';
AdminBro.registerAdapter({ Database, Resource });

const adminBro = new AdminBro({
    resources: [{ resource: TaxNexusRegion }],
    rootPath: '/admin',
});

TaxNexusRegion TypeORM Entity

import {
  Column,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
  BaseEntity,
} from 'typeorm';

@Entity('tax_nexus_region')
export class TaxNexusRegion extends BaseEntity {
  @PrimaryGeneratedColumn({
    type: 'bigint',
    name: 'id',
  })
  id: string;

  @Column('character varying', {
    nullable: false,
    name: 'region',
  })
  region: string;

  @Column('character varying', {
    nullable: false,
    name: 'region_code',
  })
  region_code: string;

  @Column('character varying', {
    nullable: false,
    name: 'country',
  })
  country: string;

  @Column('character varying', {
    nullable: false,
    name: 'country_code',
  })
  country_code: string;

  @Column('timestamp with time zone', {
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    name: 'created',
  })
  created: Date;

  @Column('timestamp with time zone', {
    nullable: false,
    default: () => 'CURRENT_TIMESTAMP',
    name: 'updated',
  })
  updated: Date;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions