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

[Feature request] Add dependencies between entities that don't have any direct relationship #167

Open
chepix10 opened this issue Apr 28, 2021 · 0 comments
Assignees

Comments

@chepix10
Copy link

Firstly, I'd like to thank all who have work on this package so far. It's awesome!

I struggled a little bit to achieve this next example and I think it could be a nice feature in the future.

So, let's say I have 5 entities. Accounts, Products, AccountProducts, Targets and TargetAccountProducts There is a direct relationship between Accounts and Products with AccountProducts so whenever I run my fixtures the order of creation is correctly set as AccountProducts is ran at the end. However, Targets is not directly related to any of the previous entities, so it usually gets created first or after Accounts and Products and TargetAccountProducts are created on a trigger of Targets so when the trigger is ran, there are still no AccountProducts created and it's ok for it to assume it should not create any relationship between the target and the account products. This is the part where the new feature will come in handy. To be able to setup in the configuration of the fixture the indirect relationships with other entities so the order of creation is altered and the trigger can see the generated AccountProducts.

The feature might be able to be set up like this:

`
entity: Target
depends:

  • AccountProduct
    items:
    target{1..40}:
    id: ($current)
    `

Currently this can be achieved by adding a field that actually relates to the entity and then delete it in the Processor
Target.yml
entity: Target processor: ../processor/TargetProcessor items: target{1..40}: id: ($current) accountProductId: '@accountProduct($current)'
TargetProcessor.ts
`
import { IProcessor } from 'typeorm-fixtures-cli';
import Target from 'entities/target.entity';

export default class TargetProcessor implements IProcessor {
preProcess?(name: string, object: any): any | Promise {
const processedObject = { ...object };
delete processedObject.accountProductId;
return processedObject;
}
}
`

If you require more information let me know

@chepix10 chepix10 changed the title [Feature request] Add dependencies between entities that don't have any relationship [Feature request] Add dependencies between entities that don't have any direct relationship Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants