Can't generate DBML with a database having many-to-many relation
Opened this issue · 2 comments
When I try to generate DBML for a database with a many-to-many relation, it fails with:
Cannot read properties of undefined (reading 'fieldIds')
Here is a reproduction code:
const content = `Table users {
id int [pk]
}
Table projects {
id int [pk]
}
Ref: projects.id <> users.id // many-to-many
`
const db: Database = (new Parser(undefined)).parse(content, 'dbmlv2')
const res = ModelExporter.export(db, 'dbml', false)
The error is on the last line.
I also tried with a few variations:
- use
'dbml'
format instead of'dbmlv2'
- replace the last line with
ModelExporter.export(db.normalize(), 'dbml', true)
- inline relation (
id int [pk, ref: <> users.id]
)
They all fail the same.
If I remove the many-to-many relation, it works well.
Am I doing something bad?
Hello, @loicknuchel.
Thank you for pointing this out. You are not doing it wrong.
Currently, we haven't handled the part of exporting to dbml for model_structure with n-n relationships (only when exporting to SQLs did we turn them into two one-to-many relationships). The reason for this is that n-n concepts are only presented in dbml, so there is no use case for converting n-n relationships from dbml to dbml.
I hope this explanation helps.
Thanks for the explanation.
Indeed the n-n relationships are not native to SQL databases but seems native to other databases, didn't know either ^^
I feel it's a bit strange to have a parser and a generator but they don't match on feature set: it's possible to write n-n relations in DBML but not to generate them ^^
Is it something you may change in the future or do you think it should stay like this?