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

Do postData fields have to be exactly the same as the entity columns in order to use @EntityFromBody()? #1

Open
laukaichung opened this issue Feb 9, 2017 · 1 comment

Comments

@laukaichung
Copy link

laukaichung commented Feb 9, 2017

I have this entity

@Entity()
export class Post{
    @PrimaryGeneratedColumn()
    post_id: number;

    @Column({type:'string'})
    comment:string;

    @Column({type:'smallint'})
    category:number;

    
    @AfterLoad()
    convertsth(){
    }

    @BeforeInsert()
    async purifyInsert() {
    }

    @BeforeUpdate()
    async purifyUpdate(){
    }
}

It seems that @EntityFromBody won't work when there are extra unrelated fields. The post body has to be entirely the same as the entity. I can't pass extra fields for non database stuff like a form token alongside the entity data or it will throw TypeError: Cannot read property 'prototype' of undefined. Is that true?

------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="post_id"

11
------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="comment"

some comment.....

------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="category"

2

------WebKitFormBoundary5ZQxKuZB8zxZpyVo
Content-Disposition: form-data; name="token"

dfsfdsdsfdsfdfsdsf

Error:

TypeError: Cannot read property 'prototype' of undefined
    at Broadcaster.isAllowedListener (/home/node/src/subscriber/Broadcaster.ts:247:71)
    at /home/node/src/subscriber/Broadcaster.ts:58:92
    at Array.filter (native)
    at Broadcaster.<anonymous> (/home/node/src/subscriber/Broadcaster.ts:58:14)
    at step (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:32:23)
    at Object.next (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:13:53)
    at /home/node/node_modules/typeorm/subscriber/Broadcaster.js:7:71
    at __awaiter (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:3:12)
    at Broadcaster.broadcastBeforeInsertEvent (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:104:16)
    at /home/node/src/subscriber/Broadcaster.ts:31:67
    at Array.map (native)
    at Broadcaster.<anonymous> (/home/node/src/subscriber/Broadcaster.ts:31:47)
    at step (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:32:23)
    at Object.next (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:13:53)
    at /home/node/node_modules/typeorm/subscriber/Broadcaster.js:7:71
    at __awaiter (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:3:12)
    at Broadcaster.broadcastBeforeEventsForAll (/home/node/node_modules/typeorm/subscriber/Broadcaster.js:57:16)
    at SubjectOperationExecutor.<anonymous> (/home/node/src/persistence/SubjectOperationExecutor.ts:111:47)
    at step (/home/node/node_modules/typeorm/persistence/SubjectOperationExecutor.js:32:23)
    at Object.next (/home/node/node_modules/typeorm/persistence/SubjectOperationExecutor.js:13:53)
    at fulfilled (/home/node/node_modules/typeorm/persistence/SubjectOperationExecutor.js:4:58)
    at process._tickDomainCallback (internal/process/next_tick.js:129:7)
@laukaichung laukaichung changed the title Does postData fields have to be exactly the same as the entity columns in order to use @EntityFromBody()? Does postData field have to be exactly the same as the entity columns in order to use @EntityFromBody()? Feb 9, 2017
@laukaichung laukaichung changed the title Does postData field have to be exactly the same as the entity columns in order to use @EntityFromBody()? Do postData fields have to be exactly the same as the entity columns in order to use @EntityFromBody()? Feb 9, 2017
@pleerock
Copy link
Member

pleerock commented Jun 7, 2017

Its not suppose to work with form data. It suppose to work with json data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants