Skip to content

Entity Factory - #3962

Merged
pleerock merged 3 commits into
typeorm:nextfrom
nicomouss:entity-factory
Apr 29, 2019
Merged

pleerock merged 3 commits into
typeorm:nextfrom
nicomouss:entity-factory

Conversation

@nicomouss

Copy link
Copy Markdown

Following PR #3910

Implemented Old Entity Factory.
Added optional EntityMetadata parameter to createEntity method.
Created documentation.

…er to createEntity method. Created documentation.
@nicomouss

Copy link
Copy Markdown
Author

@pleerock When you review and merge this PR, would you mind also exporting EntityFactoryInterface from typeorm.

I forgot to add this line in src/index.ts:

export {EntityFactoryInterface} from "./entity-factory/EntityFactoryInterface";

@Kononnable

Copy link
Copy Markdown
Contributor

The only names I came up with are EntityFactoryWithInitialization and EntityFactoryWithoutInitialization. They're long etc. but I doubt in year or so we will remember what is the difference betweenOldEntityFactory and DefaultEntityFactory. There is also a question what if we decide to change defaults to something new in the future.

@Kononnable Kononnable mentioned this pull request Apr 11, 2019
let connections: Connection[];
before(async () => connections = await createTestingConnections({
entities: [Post, Blog, Category, UserEntity, QuestionEntity],
entityFactory: new OldEntityFactory()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need it now? Are tests failing without old entity factory now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repository.create().type.should.be.equal("question"); // make sure this is our Question function

Yes, we need it, otherwise this line is failing. With new entity factory fields aren't initialized. We could remove that part of test if we don't want to use OldEntityFactory(if it's just temporary).

before(async () => connections = await createTestingConnections({
entities: [__dirname + "/entity/*{.js,.ts}"],
subscribers: [__dirname + "/subscriber/*{.js,.ts}"],
entityFactory: new OldEntityFactory()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need it now? Are those tests failing without old entity factory now?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above - fields are initialized. To make it work without OldEntityFactory we would have to change them to check for undefined values.

loadedPost!.inserted.should.be.equal(false);

@@ -0,0 +1,14 @@
import { EntityFactoryInterface } from './EntityFactoryInterface';

export class OldEntityFactory implements EntityFactoryInterface {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively we could just point code example in the changelog how user can do same without this being in the codebase. Im okay with OldEntityFactory name btw since it would be very temporary.

@pleerock

Copy link
Copy Markdown
Member

@pleerock When you review and merge this PR, would you mind also exporting EntityFactoryInterface from typeorm.

I forgot to add this line in src/index.ts:

export {EntityFactoryInterface} from "./entity-factory/EntityFactoryInterface";

export it if you need it

@nicomouss

Copy link
Copy Markdown
Author

@pleerock When you review and merge this PR, would you mind also exporting EntityFactoryInterface from typeorm.
I forgot to add this line in src/index.ts:

export {EntityFactoryInterface} from "./entity-factory/EntityFactoryInterface";

export it if you need it

I don't need it, but some people might it if they want to implement a factory class that implements EntityFactoryInterface.

Thanks @Kononnable for exporting that interface.

@pleerock

Copy link
Copy Markdown
Member

@Kononnable can we merge it?

@Kononnable

Copy link
Copy Markdown
Contributor

Yes, I think we can merge it.

@pleerock
pleerock merged commit 2a01070 into typeorm:next Apr 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants