attribute seeder
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import type { EntityManager } from '@mikro-orm/core';
|
||||
import { Attribute } from 'src/modules/product/entities/attribute.entity';
|
||||
import { attributeValueData } from './data/attribute-value.data';
|
||||
import { AttributeValue } from 'src/modules/product/entities/attribute-value.entity';
|
||||
|
||||
export class AttributeValueSeeder {
|
||||
async run(
|
||||
em: EntityManager,
|
||||
|
||||
): Promise<void> {
|
||||
const attributes = await em.findAll(Attribute)
|
||||
for (const attr of attributes) {
|
||||
|
||||
const attrValues = attributeValueData.filter(a => a.attributeName === attr.name)
|
||||
|
||||
for (const av of attrValues) {
|
||||
|
||||
const a= em.create(AttributeValue, {
|
||||
value: av.value,
|
||||
attribute: attr
|
||||
});
|
||||
|
||||
em.persist(a)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
await em.flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user