Relationships
Link schemas together to build complex, interconnected data structures without repeating yourself.
What are References?
In a real database, you don't store the full User object inside every Post. You store a reference (Foreign Key).
Mock66 allows you to do something similar, but better for mocking: Embedding. When you reference another schema, we inject the generated data of that schema directly into your response.
Creating a Relationship
You can turn any field into a reference using the Visual Builder.
- Create the Source Schema: First, create the schema you want to reuse (e.g., "User") and save it.
- Create the Parent Schema: Open a new schema (e.g., "Post").
- Add a Field: Create a new field named
author. - Change Type: Select the type dropdown and choose Ref.
- Select Target: A new dropdown will appear showing your existing schemas. Select "User".
Relationship Types
One-to-One (Single Object)
Embeds a single object.
Example: Product has one Manufacturer.
One-to-Many (Array of Objects)
Embeds a list of objects.
To do this, create an Array field first, then select a schema that will be used to populate the array.
Recursion Depth
To prevent your browser or our servers from crashing, Mock66 enforces a hard limit of 3 levels of nesting.
When the limit is reached, the generator will simply return null for that field.