You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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';
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
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:
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
The text was updated successfully, but these errors were encountered: