In mysql there are two tables which has many-to-man
y relationship, and linked by an intermediate table with foreign keys. When I used Django's inspectdb
to create models, the model is as raw as mysql, which has no many-to-many
relationship literally.
I think this model is clean. Though it has no direct many-to-many
, I can use the intermediate table for mutual lookup, e.g.
t2_object[]=SELECT* FROM intermediate_table WHERE t1.id=2;
SELECT* FROM t2 WHEREt2_id IN t2_object[]
But in this way performance may be compromised. I guess some ORM such as Hibernate uses such approach to provide two-way object persistence.
What's best practices to deal with many-to-many
in Django? Thank you.