mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
db.m2m_table_candidates(table, other_table)
This commit is contained in:
parent
b6b92980c0
commit
b9256413d2
2 changed files with 33 additions and 0 deletions
|
|
@ -297,6 +297,17 @@ class Database:
|
|||
)
|
||||
)
|
||||
|
||||
def m2m_table_candidates(self, table, other_table):
|
||||
"Returns potential m2m tables for arguments, based on FKs"
|
||||
candidates = []
|
||||
tables = {table, other_table}
|
||||
for table in self.tables:
|
||||
# Does it have foreign keys to both table and other_table?
|
||||
has_fks_to = {fk.other_table for fk in table.foreign_keys}
|
||||
if has_fks_to.issuperset(tables):
|
||||
candidates.append(table.name)
|
||||
return candidates
|
||||
|
||||
def add_foreign_keys(self, foreign_keys):
|
||||
# foreign_keys is a list of explicit 4-tuples
|
||||
assert all(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue