attribute seeder

This commit is contained in:
2026-01-27 15:38:48 +03:30
parent e2b065aa2b
commit 355d4afaa2
7 changed files with 129 additions and 7 deletions
+30
View File
@@ -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();
}
}