mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-24 01:44:31 +02:00
table.m2m(..., alter=True) option, closes #222
This commit is contained in:
parent
0b244d207a
commit
d4e00f8d01
3 changed files with 24 additions and 1 deletions
|
|
@ -2009,6 +2009,7 @@ class Table(Queryable):
|
|||
pk=DEFAULT,
|
||||
lookup=None,
|
||||
m2m_table=None,
|
||||
alter=False,
|
||||
):
|
||||
if isinstance(other_table, str):
|
||||
other_table = self.db.table(other_table, pk=pk)
|
||||
|
|
@ -2045,7 +2046,9 @@ class Table(Queryable):
|
|||
)
|
||||
# Ensure each record exists in other table
|
||||
for record in records:
|
||||
id = other_table.insert(record, pk=pk, replace=True).last_pk
|
||||
id = other_table.insert(
|
||||
record, pk=pk, replace=True, alter=alter
|
||||
).last_pk
|
||||
m2m_table.insert(
|
||||
{
|
||||
"{}_id".format(other_table.name): id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue