How to seed a factory which has a oneToMany relationship using other factory #249
Unanswered
yesid-lopez
asked this question in
Q&A
Replies: 1 comment
-
I tried this one an looks like it works export default class CommonAreaSeeder implements Seeder {
public async run(
dataSource: DataSource,
factoryManager: SeederFactoryManager,
): Promise<any> {
const commonAreaFactory = await factoryManager.get(CommonArea);
const availableDayFactory = await factoryManager.get(AvailableDay);
const commonAreas = await commonAreaFactory.saveMany(3);
commonAreas.forEach(
async (commonArea) => await availableDayFactory.saveMany(3, { commonArea }),
);
}
} Output [
{
"id": "656d9c6e-fe4b-4e46-a13a-5b0fbe63b0ac",
"name": "Cancha Futbol A",
"availableDays": [
{
"id": "c6dde343-9677-4d40-85b9-5a2f790cc436",
"name": "Wednesday",
"from": "11:01 PM",
"until": "04:01 AM"
},
{
"id": "c74203bd-b534-4fb0-846b-ed193516ec9b",
"name": "Thursday",
"from": "11:01 PM",
"until": "02:01 AM"
},
{
"id": "7b1c41e7-b012-4fa1-8d0d-303b31205b69",
"name": "Friday",
"from": "11:01 PM",
"until": "12:01 AM"
}
]
},
{
"id": "97c390ae-cab4-4932-bee0-3e39504c65f2",
"name": "Turko",
"availableDays": [
{
"id": "0bbb5491-bf27-4d90-b105-ff624410938a",
"name": "Monday",
"from": "11:01 PM",
"until": "08:01 AM"
},
{
"id": "8dafa66f-c942-4b1b-9cb4-11ee2106d5fc",
"name": "Tuesday",
"from": "11:01 PM",
"until": "04:01 AM"
},
{
"id": "8095f0e4-1d3a-475c-bd10-3650fa206b85",
"name": "Sunday",
"from": "11:01 PM",
"until": "07:01 AM"
}
]
},
{
"id": "afe2e9e7-26fc-4ca0-9e9a-46b503a8e0f2",
"name": "Cancha Futbol B",
"availableDays": [
{
"id": "98e5f90f-744a-47d1-a8be-1cdb9a72973a",
"name": "Thursday",
"from": "11:01 PM",
"until": "06:01 AM"
},
{
"id": "fc4f5bff-d5d8-40f1-b84a-ff129d8b94e9",
"name": "Friday",
"from": "11:01 PM",
"until": "02:01 AM"
},
{
"id": "2b0a61a4-7e4e-4c81-b95a-be97ebd053ca",
"name": "Monday",
"from": "11:01 PM",
"until": "02:01 AM"
}
]
}
] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey, I'm trying to seed my db for a specific entity, and I would like to take advantage of other factory to populate my entities. As you can see, I'm expecting to create 4 common areas with an array of available days, however only one entity is created in that way, the other ones are empty as you can see in the last json:
Beta Was this translation helpful? Give feedback.
All reactions