Skip to content

Commit 0ed7c7c

Browse files
chore: add test
1 parent bacd6d9 commit 0ed7c7c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/test_update.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from sqlmodel import Field, SQLModel, create_engine
2+
3+
4+
def test_sqlmodel_update():
5+
class Organization(SQLModel, table=True):
6+
id: int = Field(default=None, primary_key=True)
7+
name: str
8+
headquarters: str
9+
10+
class OrganizationUpdate(SQLModel):
11+
name: str
12+
13+
engine = create_engine("sqlite:///", echo=True)
14+
SQLModel.metadata.create_all(engine)
15+
16+
org = Organization(name="Example Org", city="New York", headquarters="NYC HQ")
17+
org_in = OrganizationUpdate(name="Updated org")
18+
org.sqlmodel_update(
19+
org_in,
20+
update={
21+
"headquarters": "-", # This field is in Organization, but not in OrganizationUpdate
22+
},
23+
)

0 commit comments

Comments
 (0)