Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a built-in way to generate set of entities having relationships between each others #5025

Open
dubzzz opened this issue May 27, 2024 · 1 comment

Comments

@dubzzz
Copy link
Owner

dubzzz commented May 27, 2024

💡 Idea

Generating structures being tied to one another in a many-to-many or one-to-many relationship in fast-check is not trivial. While feasible it requires our users to come up with advanced and complex options. The two tickets below are asking for it:

As the case is pretty general, we should probably come up with a built-in utility hiding all this complexity and able to generate a simple database content based on a provided schema. The helpers for many-to-many and many-to-one initiated by @gruhn sounds like great ideas to start to think of it.

Disclaimer: while the issue has been opened, there is no certainty that there will be a built-in helpers for that purpose, but at least we can start thinking of it: api, implem...

@dubzzz
Copy link
Owner Author

dubzzz commented May 27, 2024

At some point it makes me thinking to letrec even if 1. letrec does not support such need 2. the drafted code below would not work. But I feel having it in mind can help to draft a potential API:

const dataset = fc.dataset((tie) => ({
  // first table
  department: fc.record({
    id: fc.uuidV4(),
    name: fc.string(),
  }),
  // second table
  employee: fc.record({
    id: fc.uuidV4(),
    departmentId: tie('department', 'id'), // we will also need optional, many... maybe nested properties
    firstName: fc.string(),
    lastName: fc.string(),
  }),
}))

Maybe to ease our task, the internal declarations should not be wrapped within records. Indeed records will hide us what's could be actionable to get proper info on how to create the id of department. By dropping it we could possibly know enough on the two nested structures to magically generate them.

We should probably have a way to give a set of unicity constraints for each structure (id is one of them).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant