Skip to content

Commit 4b21fe6

Browse files
authored
Supporting ManyToMany / through models (makecodes#5)
Consider the following example: ``` class AModel(Model): a_id = CharField(max_length=32, unique=True, primary_key=True) class ABs(Model): a = ForeignKey("appname.AModel", on_delete=CASCADE) b = ForeignKey("appname.BModel", on_delete=CASCADE, null=True, default=None) class BModel(Model): b_id = CharField(max_length=32, unique=True, primary_key=True) a_models = ManyToManyField(related_name="b_models", through="appname.ABs", to="appname.AModel") ``` Running `python manage.py dbml > out.dbml` and `dbdocs build ./out.dbml` leads to ``` ✖ Failed: You have syntax error in out.dbml line 612 column 6. Can't find field "b_id" in table "AModel" ``` The fix I suggest resolves this issue
1 parent c4680c0 commit 4b21fe6

File tree

1 file changed

+1
-1
lines changed
  • django_dbml/management/commands

1 file changed

+1
-1
lines changed

django_dbml/management/commands/dbml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def handle(self, *app_labels, **kwargs):
134134
"table_from": table_name_m2m,
135135
"table_from_field": field.m2m_reverse_name(),
136136
"table_to": field.related_model.__name__,
137-
"table_to_field": field.m2m_target_field_name(),
137+
"table_to_field": field.m2m_reverse_target_field_name(),
138138
}
139139
)
140140
tables[table_name_m2m]["fields"][field.m2m_reverse_name()] = {

0 commit comments

Comments
 (0)