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

How to set embedded values? #145

Open
brussee opened this issue Jun 24, 2020 · 5 comments
Open

How to set embedded values? #145

brussee opened this issue Jun 24, 2020 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@brussee
Copy link

brussee commented Jun 24, 2020

Software Version(s)
typeorm-fixtures 1.7.0
Node 14.4.0
Yarn 1.22.4
Operating System Debian 10
$ node -r tsconfig-paths/register -r ts-node/register node_modules/.bin/fixtures --config ./apps/my-api/src/db.config.ts --sync ./fixtures
Progress  [██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 20% | ETA: 1s | 1/5 user1 
Fail fixture loading: entity[propertyPath][this.propertyName] is not a function
TypeError: entity[propertyPath][this.propertyName] is not a function
    at EntityListenerMetadata.callEntityEmbeddedMethod (/nest-pkgs/src/metadata/EntityListenerMetadata.ts:89:52)
    at EntityListenerMetadata.execute (/nest-pkgs/src/metadata/EntityListenerMetadata.ts:73:14)
    at /nest-pkgs/src/subscriber/Broadcaster.ts:38:54
    at Array.forEach (<anonymous>)
    at Broadcaster.broadcastBeforeInsertEvent (/nest-pkgs/src/subscriber/Broadcaster.ts:36:44)
    at /nest-pkgs/src/persistence/SubjectExecutor.ts:211:81
    at Array.forEach (<anonymous>)
    at SubjectExecutor.broadcastBeforeEventsForAll (/nest-pkgs/src/persistence/SubjectExecutor.ts:211:33)
    at SubjectExecutor.<anonymous> (/nest-pkgs/src/persistence/SubjectExecutor.ts:108:38)
    at step (/nest-pkgs/node_modules/typeorm/node_modules/tslib/tslib.js:141:27)
error Command failed with exit code 1.
entity: User
items:
    user1:
        authEmail: me@domain.com
        auth.email: me@domain.com
        auth.Email: me@domain.com
        auth:
            authEmail: me@domain.com
        __call:
            auth.setEmailVerified:
                - true
@Entity()
export class User {
    @PrimaryGeneratedColumn('uuid')
    uuid?: string;

    @ValidateNested()
    @Column(() => LocalAuth)
    auth?: LocalAuth;
}
export abstract class LocalAuth {
    @IsEmail()
    @Index({unique: true})
    @Column({comment: 'email = username', unique: true})
    email?: string;

    @BeforeInsert()
    emailToLowerCase() {
        this.email = this.email?.toLowerCase();
    }

    @IsDate()
    @Column({nullable: true})
    email_verified_at?: Date;

    setEmailVerified(verified: boolean) {
        if (verified) {
            this.email_verified_at = new Date();
        } else {
            this.email_verified_at = undefined;
        }
        return this;
    }
}
@brussee brussee added the bug Something isn't working label Jun 24, 2020
@brussee
Copy link
Author

brussee commented Jun 24, 2020

If I remove the part:

        auth:
            authEmail: me@domain.com

then I get:

$ node -r tsconfig-paths/register -r ts-node/register node_modules/.bin/fixtures --config ./apps/my-api/src/db.config.ts --sync ./fixtures
Progress  [██████████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 20% | ETA: 1s | 1/5 user1 
Fail fixture loading: null value in column "authEmail" violates not-null constraint
QueryFailedError: null value in column "authEmail" violates not-null constraint
    at new QueryFailedError (/nest-pkgs/src/error/QueryFailedError.ts:9:9)
    at Query.callback (/nest-pkgs/src/driver/postgres/PostgresQueryRunner.ts:178:30)
    at Query.handleError (/nest-pkgs/node_modules/pg/lib/query.js:146:19)
    at Connection.connectedErrorMessageHandler (/nest-pkgs/node_modules/pg/lib/client.js:233:17)
    at Connection.emit (events.js:315:20)
    at /nest-pkgs/node_modules/pg/lib/connection.js:109:10
    at Parser.parse (/nest-pkgs/node_modules/pg-protocol/src/parser.ts:107:9)
    at TLSSocket.<anonymous> (/nest-pkgs/node_modules/pg-protocol/src/index.ts:7:48)
    at TLSSocket.emit (events.js:315:20)
    at addChunk (_stream_readable.js:302:12) {
  length: 381,
  severity: 'ERROR',
  code: '23502',
  detail: 'Failing row contains (6c6f9867-9fa8-48a7-aec1-431a4de02f83, null, null).',
  hint: undefined,
  position: undefined,
  internalPosition: undefined,
  internalQuery: undefined,
  where: undefined,
  schema: 'public',
  table: 'user',
  column: 'authEmail',
  dataType: undefined,
  constraint: undefined,
  file: 'execMain.c',
  line: '1960',
  routine: 'ExecConstraints',
  query: 'INSERT INTO "user"("uuid", "authEmail", "authEmail_verified_at") VALUES (DEFAULT, DEFAULT, DEFAULT) RETURNING "uuid"',
  parameters: []
}
error Command failed with exit code 1.

@uRTLy
Copy link

uRTLy commented Aug 30, 2020

any answers to this ?

@singlesly
Copy link

try to use

auth:
  email: me@domain.com

@brussee
Copy link
Author

brussee commented Mar 24, 2021

try to use

auth:
  email: me@domain.com

Nothing is saved in the database if I try that.

I've worked around this issue by creating a separate fixture file for entity: LocalAuth.

@GrolaElmahdi
Copy link

GrolaElmahdi commented Apr 27, 2024

@brussee I found another work around if this can help:

Since your LocalAuth is a non entity class, you can create a post (or pre) processor for your target User entity, then use the faker inside your PostProcessor to populate your LocalAuth Class.

It works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants