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

Improve relationship declaration #57

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/schemas/generateMegaRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async function generateMegaRecord(schema) {
let newRecord = {}
// ensure the new record obeys the foriegn key constraint
// specified in the relationship
newRecord[relationship.field] = existingRecord[_meta.key]
newRecord[relationship.child_field] = existingRecord[relationship.parent_field]
if (!megaRecord[relationship.topic]) {
megaRecord[relationship.topic] = {"key": _meta.key, "records": []}
}
Expand Down
31 changes: 17 additions & 14 deletions tests/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"relationships": [
{
"topic": "mz_datagen_posts",
"field": "user_id",
"parent_field": "id",
"child_field": "user_id",
"records_per": 2
}
]
Expand All @@ -15,7 +16,7 @@
"phone": "phone.imei",
"website": "internet.domainName"
},
"id": "datatype.uuid",
"id": "datatype.number(100)",
"name": "internet.userName",
"email": "internet.exampleEmail",
"phone": "phone.imei",
Expand All @@ -30,33 +31,35 @@
"relationships": [
{
"topic": "mz_datagen_comments",
"field": "post_id",
"parent_field": "id",
"child_field": "post_id",
"records_per": 2
}
]
},
"id": "datatype.uuid",
"user_id": "datatype.uuid",
"id": "datatype.number(1000)",
"user_id": "datatype.number(100)",
"title": "lorem.sentence",
"body": "lorem.paragraph"
},
{
"_meta": {
"topic": "mz_datagen_comments",
"key": "user_id",
"relationships": [
{
"key": "id",
"relationships": [
{
"topic": "mz_datagen_users",
"field": "id",
"parent_field": "user_id",
"child_field": "id",
"records_per": 1
}
]
]
},
"id": "datatype.uuid",
"user_id": "datatype.uuid",
"id": "datatype.number(2000)",
"user_id": "datatype.number(100)",
"body": "lorem.paragraph",
"post_id": "datatype.uuid",
"post_id": "datatype.number(1000)",
"views": "datatype.number({\"min\": 100, \"max\": 1000})",
"status": "datatype.number(1)"
}
]
]