mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-09-11 02:54:23 +02:00
Allow table objects to be passed to .m2m()
This commit is contained in:
parent
d96a8f149e
commit
5516175ca6
2 changed files with 29 additions and 8 deletions
|
|
@ -43,6 +43,19 @@ def test_insert_m2m_list(fresh_db):
|
|||
] == dogs_humans.foreign_keys
|
||||
|
||||
|
||||
def test_m2m_with_table_objects(fresh_db):
|
||||
dogs = fresh_db.table("dogs", pk="id")
|
||||
humans = fresh_db.table("humans", pk="id")
|
||||
dogs.insert({"id": 1, "name": "Cleo"}).m2m(
|
||||
humans, [{"id": 1, "name": "Natalie D"}, {"id": 2, "name": "Simon W"}]
|
||||
)
|
||||
expected_tables = {"dogs", "humans", "dogs_humans"}
|
||||
assert expected_tables == set(fresh_db.table_names())
|
||||
assert 1 == dogs.count
|
||||
assert 2 == humans.count
|
||||
assert 2 == fresh_db["dogs_humans"].count
|
||||
|
||||
|
||||
def test_m2m_lookup(fresh_db):
|
||||
people = fresh_db.table("people", pk="id")
|
||||
people.insert({"name": "Wahyu"}).m2m("tags", lookup={"tag": "Coworker"})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue