RobinCK / typeorm-fixtures

:pill: Fixtures loader for typeorm 🇺🇦
https://robinck.github.io/typeorm-fixtures/
MIT License
566 stars 45 forks source link

Extra fields in Users entity #99

Closed ishpagin closed 4 years ago

ishpagin commented 4 years ago

when I set data for Users entity I got extra fields in DB My Users entity:

import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";

@Entity()
export class Users {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ length: 100 })
  name: string;
}

I got: изображение

With other entities all good, but not with this. What can it be?

ishpagin commented 4 years ago

// Users.yml

entity: Users
parameters: {}
items:
  users1:
    name: 'admin'
ishpagin commented 4 years ago

tryed debug with ts file:


import * as path from 'path';
import { Builder, fixturesIterator, Loader, Parser, Resolver } from 'typeorm-fixtures-cli/dist';
import { createConnection, getRepository } from 'typeorm';

const loadFixtures = async (fixturesPath: string) => {
  let connection;

  try {
    connection = await createConnection();
    await connection.synchronize(true);

    const loader = new Loader();
    loader.load(path.resolve(fixturesPath));

    const resolver = new Resolver();
    const fixtures = resolver.resolve(loader.fixtureConfigs);
    const builder = new Builder(connection, new Parser());

    for (const fixture of fixturesIterator(fixtures)) {
      const entity: any = await builder.build(fixture);
      console.log(entity.constructor.name, fixture)
      // console.log out:
      // Users { parameters: {},
      // processor: undefined,
      // entity: 'Users',
      // name: 'users1',
      // data: { name: 'admin' },
      // dependencies: [] }
      await getRepository(fixture.entity).save(entity);
    }
  } catch (err) {
    throw err;
  } finally {
    if (connection) {
      await connection.close();
    }
  }
};

loadFixtures('./fixtures')
  .then(() => {
    console.log('Fixtures are successfully loaded.');
  })
  .catch(err => console.log(err));
ishpagin commented 4 years ago

It was the "nest-admin" entities, they rewrite my own entity.

/solved