Missing secondary relation connection between two tables
Self Checks
- [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
- [x] I have searched for existing issues search for existing issues, including closed ones.
Version Type
CLI Version (npm package)
Version (only for Self Hosted)
v0.4.3 + 4a6deae (2025-02-26)
Steps to reproduce
See attached schema
Expected Behavior
All the relations are correctly visualized
Actual Behavior
My Table A is connected to two row of Table B. This is the relation: "relationshipNo6": { "name": "relationshipNo6", "primaryTableName": "img_image_save", "primaryColumnName": "IMG_POST_PROCESSING_ID_DIRECT", "foreignTableName": "img_post_processing", "foreignColumnName": "IMG_POST_PROCESSING_ID", "cardinality": "ONE_TO_ONE", "updateConstraint": "NO_ACTION", "deleteConstraint": "NO_ACTION" }, "relationshipNo7": { "name": "relationshipNo7", "primaryTableName": "img_image_save", "primaryColumnName": "IMG_POST_PROCESSING_ID_SUB", "foreignTableName": "img_post_processing", "foreignColumnName": "IMG_POST_PROCESSING_ID", "cardinality": "ONE_TO_ONE", "updateConstraint": "NO_ACTION", "deleteConstraint": "NO_ACTION" } In visualization SHOW: All Fields the connection is missing
Additional Context
No response
@ac2780 I guess the file you mentioned in the description is not a schema, but a parsed object from a schema. Out of your description, I created a similar reproduction of this problem. I hope it makes scense:
- copy the following schema and save on your local PC.
- run
pnpm run build --filter @liam-hq/cli - run
node frontend/packages/cli/dist-cli/bin/cli.js erd build --input schema.json - run
npx http-server distto run the application and go to http://localhost:8080/
schema
{
"name": "testdb",
"desc": "Sample database document.",
"tables": [
{
"name": "posts",
"type": "BASE TABLE",
"comment": "Posts table",
"columns": [
{
"name": "id",
"type": "int",
"nullable": false,
"extra_def": "auto_increment"
},
{
"name": "user_id_1",
"type": "int",
"nullable": false
},
{
"name": "user_id_2",
"type": "int",
"nullable": false
}
],
"indexes": [],
"constraints": [],
"def": "",
"labels": [
{
"name": "green",
"virtual": true
},
{
"name": "red",
"virtual": true
},
{
"name": "blue",
"virtual": true
}
]
},
{
"name": "users",
"type": "BASE TABLE",
"comment": "Users table",
"columns": [
{
"name": "id",
"type": "int",
"nullable": false,
"extra_def": "auto_increment"
}
],
"indexes": [],
"constraints": [
{
"name": "PRIMARY",
"type": "PRIMARY KEY",
"def": "PRIMARY KEY (id)",
"table": "users",
"columns": ["id"]
}
],
"def": ""
}
],
"relations": [
{
"table": "users",
"columns": ["id"],
"cardinality": "zero_or_more",
"parent_table": "posts",
"parent_columns": ["user_id_1"],
"parent_cardinality": "exactly_one",
"def": "FOREIGN KEY (id) REFERENCES users (user_id_1)"
},
{
"table": "users",
"columns": ["id"],
"cardinality": "zero_or_more",
"parent_table": "posts",
"parent_columns": ["user_id_2"],
"parent_cardinality": "exactly_one",
"def": "FOREIGN KEY (id) REFERENCES users (user_id_2)"
}
],
"driver": {
"name": "mysql",
"database_version": "8.4.4",
"meta": {
"dict": {
"Functions": "Stored procedures and functions"
}
}
},
"labels": [
{
"name": "sample",
"virtual": true
},
{
"name": "tbls",
"virtual": true
}
]
}
It looks the first relation (relationship between users.id and posts_id_1) is ignored.
However I don't think this is a bug. The reason why it happens is that the table and parent_table are reversed. In this case, "table" should be "posts" and parent_table should be "users".
If I fix the schema as follows, it works as expected.
updated schema.json
{
"name": "testdb",
"desc": "Sample database document.",
"tables": [
{
"name": "posts",
"type": "BASE TABLE",
"comment": "Posts table",
"columns": [
{
"name": "id",
"type": "int",
"nullable": false,
"extra_def": "auto_increment"
},
{
"name": "user_id_1",
"type": "int",
"nullable": false
},
{
"name": "user_id_2",
"type": "int",
"nullable": false
}
],
"indexes": [],
"constraints": [],
"def": "",
"labels": [
{
"name": "green",
"virtual": true
},
{
"name": "red",
"virtual": true
},
{
"name": "blue",
"virtual": true
}
]
},
{
"name": "users",
"type": "BASE TABLE",
"comment": "Users table",
"columns": [
{
"name": "id",
"type": "int",
"nullable": false,
"extra_def": "auto_increment"
}
],
"indexes": [],
"constraints": [
{
"name": "PRIMARY",
"type": "PRIMARY KEY",
"def": "PRIMARY KEY (id)",
"table": "users",
"columns": ["id"]
}
],
"def": ""
}
],
"relations": [
{
"table": "posts",
"columns": ["user_id_1"],
"cardinality": "zero_or_more",
"parent_table": "users",
"parent_columns": ["id"],
"parent_cardinality": "exactly_one",
"def": "FOREIGN KEY (user_id_1) REFERENCES users (id)"
},
{
"table": "posts",
"columns": ["user_id_2"],
"cardinality": "zero_or_more",
"parent_table": "users",
"parent_columns": ["id"],
"parent_cardinality": "exactly_one",
"def": "FOREIGN KEY (user_id_2) REFERENCES users (id)"
}
],
"driver": {
"name": "mysql",
"database_version": "8.4.4",
"meta": {
"dict": {
"Functions": "Stored procedures and functions"
}
}
},
"labels": [
{
"name": "sample",
"virtual": true
},
{
"name": "tbls",
"virtual": true
}
]
}
I hope this reproduction will help you to solve the problem. I recommend to check your schema. Please let me know if your schema is valid but the problem still happens 😉
additional information
Version: the current latest main
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.