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

Can't generate DBML with a database having many-to-many relation #516

Open
loicknuchel opened this issue Feb 11, 2024 · 2 comments
Open

Comments

@loicknuchel
Copy link

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?

@NQPhuc
Copy link
Contributor

NQPhuc commented Feb 12, 2024

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.

@loicknuchel
Copy link
Author

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?

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

No branches or pull requests

2 participants