Faker definition for relationship properties
SalahAdDin opened this issue · comments
It is very annoying to have to create a whole object just cause one of the properties, the relationship, is not filling by default:
continueArticle: {
id: primaryKey(() => _continueId++),
title: () => faker.lorem.words(),
slug: () => faker.helpers.slugify(title),
publishedDate: () => faker.date.anytime(),
category: oneOf("category"),
thumbnail: oneOf("image"),
},
export const createContinueArticle = (relatedArticle = {}) =>
db.continueArticle.create(relatedArticle);
Is there any away to make it getting any existing object to fill the relation?
Hi, @SalahAdDin. Not sure what you are trying to achieve.
The category
is missing because you've never provided one in your example. You have to provide an initial value to the relation or update the entity with a relation for the value to appear.
db.continueArticle.create({
category: db.category.create() // or reference an existing category.
})
Once you do, the value will be set correctly.
Hi, @SalahAdDin. I'm not sure what you are trying to achieve.
The
category
is missing because you've never provided one in your example. You must provide an initial value to the relation or update the entity concerning the value to appear.db.continueArticle.create({ category: db.category.create() // or reference an existing category. })Once you do, the value will be set correctly.
That's the issue, why isn't msw/data
able to create the category entity by itself?