René's URL Explorer Experiment


Title: Issue using from_orm stripping Relationship data from models · Issue #224 · fastapi/sqlmodel · GitHub

Open Graph Title: Issue using from_orm stripping Relationship data from models · Issue #224 · fastapi/sqlmodel

X Title: Issue using from_orm stripping Relationship data from models · Issue #224 · fastapi/sqlmodel

Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I already searched in Google "How to X in...

Open Graph Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I...

X Description: First Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated searc...

Opengraph URL: https://github.com/fastapi/sqlmodel/issues/224

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Issue using from_orm stripping Relationship data from models","articleBody":"### First Check\r\n\r\n- [X] I added a very descriptive title to this issue.\r\n- [X] I used the GitHub search to find a similar issue and didn't find it.\r\n- [X] I searched the SQLModel documentation, with the integrated search.\r\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\r\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\r\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\r\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\n\r\n### Commit to Help\r\n\r\n- [X] I commit to help with one of those options 👆\r\n\r\n### Example Code\r\n\r\n```python\r\nfrom sqlmodel import SQLModel, Relationship, Field, create_engine, Session\r\nfrom typing import List, Optional, Literal\r\n\r\nengine = create_engine(\"sqlite://\", connect_args={\"check_same_thread\": False})\r\n\r\n\r\ndef create_db_and_tables():\r\n    SQLModel.metadata.create_all(engine)\r\n\r\n\r\nclass LocationBase(SQLModel):\r\n    street: str\r\n    city: str\r\n    country: str\r\n\r\n\r\nclass Location(SQLModel, table=True):\r\n    id: Optional[int] = Field(default=None, primary_key=True)\r\n\r\n    employee_id: Optional[int] = Field(default=None, foreign_key=\"employee.id\")\r\n    employee: \"Employee\" = Relationship(back_populates='locations')\r\n\r\n\r\nclass EmployeeBase(SQLModel):\r\n    name: str\r\n    job: str\r\n\r\n\r\nclass Employee(EmployeeBase, table=True):\r\n    id: Optional[int] = Field(default=None, primary_key=True)\r\n    locations: List[Location] = Relationship(back_populates=\"employee\")\r\n\r\n\r\nclass EmployeeCreate(EmployeeBase):\r\n    locations: List[Location]\r\n\r\n\r\ndef create_employees():\r\n    locations = [Location(street='State St.', city='New York', country='USA')]\r\n    e = EmployeeCreate(name='Test Employee', job='Test Job', locations=locations)\r\n\r\n    employee = Employee.from_orm(e) # this strips the locations list from the Employee object\r\n    print(employee)\r\n\r\n    # You have to manually readd the locations before sending data to the DB.\r\n    # If you skip this line then no location data will be added to the DB.\r\n    e.locations = locations\r\n\r\n    # Now you can commit.\r\n\r\n\r\ndef main():\r\n    create_db_and_tables()\r\n    create_employees()\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n```\r\n\r\n\r\n### Description\r\n\r\nApologies if this seems trivial! When using SQLModel's `from_orm` method the relationship data is stripped from the outputted model. I think that there may be an issue with how the `from_orm` method works in SQLModel but I can't diagnose where the data is actually stripped.\r\n\r\nI found a similar issue here: https://github.com/samuelcolvin/pydantic/issues/1334. The difference is that typically (before SQLModel) most models refer to other Pydantic models instead of other relationships. This could be an example of a typical model relationship in Pydantic:\r\n\r\n```\r\nfrom pydantic import BaseModel\r\n\r\n\r\nclass Employee(BaseModel):\r\n    id: int\r\n    name: str\r\n    type: str\r\n\r\n\r\nclass Address(BaseModel):\r\n    id: int\r\n    city: str\r\n    employee: Employee\r\n\r\n    class Config:\r\n        orm_mode = True\r\n\r\ne = Employee(id=1, name='Test', type='pydantic')\r\na= Address(id=1, city='New York', employee=e)\r\n\r\nprint(a.from_orm(a))\r\n```\r\n\r\n(This correctly outputs `id=1 city='New York' employee=Employee(id=1, name='Test', type='pydantic')`)\r\n\r\nIt's not a big deal to readd the models but it becomes tedious if you have many models to manage. I was wondering if anyone else had this issue and I couldn't find it referenced anywhere else. Thank you so much!\r\n\r\n### Operating System\r\n\r\nmacOS\r\n\r\n### Operating System Details\r\n\r\n_No response_\r\n\r\n### SQLModel Version\r\n\r\n0.0.6\r\n\r\n### Python Version\r\n\r\n3.8.1\r\n\r\n### Additional Context\r\n\r\n_No response_","author":{"url":"https://github.com/res234","@type":"Person","name":"res234"},"datePublished":"2022-01-15T08:33:21Z","url":"https://github.com/fastapi/sqlmodel/issues/224"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:6b68ccac-9ad3-aa3f-da6d-442af549b4b9
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBFDA:284967:1F12DA:2A489E:6AFE18AA
html-safe-nonce435bc0dc7a1900de914f67aaf47aa9dd641903f290e4776b715c3857161ad032
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRkRBOjI4NDk2NzoxRjEyREE6MkE0ODlFOjZBRkUxOEFBIiwidmlzaXRvcl9pZCI6IjY4NTkxMDgzNTE2OTk5ODI1MDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac94420d21fb281ed8df7497cc7fcc258b575655f268d691a1179029f221ef6f92
hovercard-subject-tagissue:1104639543
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fastapi/sqlmodel/224/issue_layout
twitter:imagehttps://opengraph.githubassets.com/13fa83796e018b521c1c68c01a33bba156818cf82384fc82c42a224f9d09bfcf/fastapi/sqlmodel/issues/224
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/13fa83796e018b521c1c68c01a33bba156818cf82384fc82c42a224f9d09bfcf/fastapi/sqlmodel/issues/224
og:image:altFirst Check I added a very descriptive title to this issue. I used the GitHub search to find a similar issue and didn't find it. I searched the SQLModel documentation, with the integrated search. I...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameres234
hostnamegithub.com
expected-hostnamegithub.com
Noned0525ab1464526bf4532a5551aa348cf100dff75ef808a96fc67a08b1d946aa9
turbo-cache-controlno-preview
go-importgithub.com/fastapi/sqlmodel git https://github.com/fastapi/sqlmodel.git
octolytics-dimension-user_id156354296
octolytics-dimension-user_loginfastapi
octolytics-dimension-repository_id399495186
octolytics-dimension-repository_nwofastapi/sqlmodel
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id399495186
octolytics-dimension-repository_network_root_nwofastapi/sqlmodel
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasefef3993a71fa20f7be8e167132fbf9619bc66e12
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/fastapi/sqlmodel/issues/224#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F224
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F224
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=fastapi%2Fsqlmodel
Reloadhttps://github.com/fastapi/sqlmodel/issues/224
Reloadhttps://github.com/fastapi/sqlmodel/issues/224
Reloadhttps://github.com/fastapi/sqlmodel/issues/224
fastapihttps://github.com/fastapi
sqlmodelhttps://github.com/fastapi/sqlmodel
Codehttps://github.com/fastapi/sqlmodel
Issues1 (1)https://github.com/fastapi/sqlmodel/issues
Pull requests53 (53)https://github.com/fastapi/sqlmodel/pulls
Discussionshttps://github.com/fastapi/sqlmodel/discussions
Actionshttps://github.com/fastapi/sqlmodel/actions
Projectshttps://github.com/fastapi/sqlmodel/projects
Security and qualityhttps://github.com/fastapi/sqlmodel/security
Insightshttps://github.com/fastapi/sqlmodel/insights
https://github.com/fastapi/sqlmodel
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/224
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/224
Issue using from_orm stripping Relationship data from modelshttps://github.com/fastapi/sqlmodel/issues/224#top
investigatehttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22investigate%22
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
https://github.com/res234
res234https://github.com/res234
on Jan 15, 2022https://github.com/fastapi/sqlmodel/issues/224#issue-1104639543
Pydantichttps://github.com/samuelcolvin/pydantic
SQLAlchemyhttps://github.com/sqlalchemy/sqlalchemy
pydantic/pydantic#1334https://github.com/pydantic/pydantic/issues/1334
res234https://github.com/res234
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
on Jan 15, 2022https://github.com/fastapi/sqlmodel/issues/224#event-5898742445
https://github.com/mafetoro92
mafetoro92https://github.com/mafetoro92
on Jan 17, 2022https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1014961123
https://github.com/Butch78
Butch78https://github.com/Butch78
on Feb 5, 2022https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1030570329
https://user-images.githubusercontent.com/19205392/152633149-f319e3f5-ee94-4027-92b1-353c9f3b02ec.png
https://user-images.githubusercontent.com/19205392/152633203-51f3ee7c-ad5a-464c-ab69-3290b58b64d1.png
@res234https://github.com/res234
https://github.com/res234
res234https://github.com/res234
on Feb 5, 2022https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1030657414
@Butch78https://github.com/Butch78
https://sqlmodel.tiangolo.com/tutorial/fastapi/relationships/#models-with-relationshipshttps://sqlmodel.tiangolo.com/tutorial/fastapi/relationships/#models-with-relationships
https://github.com/Butch78
Butch78https://github.com/Butch78
on Feb 5, 2022https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1030700330
@res234https://github.com/res234
https://github.com/res234
res234https://github.com/res234
on Feb 5, 2022https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1030708580
@Butch78https://github.com/Butch78
https://github.com/dansmachina
dansmachinahttps://github.com/dansmachina
on Feb 21, 2022https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1046635660
https://github.com/Phifo
Phifohttps://github.com/Phifo
on Nov 16, 2022https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1317175623
tiangolohttps://github.com/tiangolo
investigatehttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22investigate%22
on Nov 17, 2022https://github.com/fastapi/sqlmodel/issues/224#event-7830506318
https://github.com/ckudera
ckuderahttps://github.com/ckudera
on Jun 14, 2023https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1590801277
https://github.com/JeffTax
JeffTaxhttps://github.com/JeffTax
on Aug 8, 2023https://github.com/fastapi/sqlmodel/issues/224#issuecomment-1670022980
https://github.com/Wouterkoorn/sqlalchemy-pydantic-ormhttps://github.com/Wouterkoorn/sqlalchemy-pydantic-orm
https://github.com/whugarra
whugarrahttps://github.com/whugarra
on Jul 15, 2024https://github.com/fastapi/sqlmodel/issues/224#issuecomment-2227897252
https://github.com/prurph
prurphhttps://github.com/prurph
on Jul 20, 2024https://github.com/fastapi/sqlmodel/issues/224#issuecomment-2240895479
https://github.com/YuriiMotov
YuriiMotovhttps://github.com/YuriiMotov
on Aug 27, 2025https://github.com/fastapi/sqlmodel/issues/224#issuecomment-3227122568
#6https://github.com/fastapi/sqlmodel/issues/6
YuriiMotovhttps://github.com/YuriiMotov
duplicatehttps://github.com/fastapi/sqlmodel/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Aduplicate
Flexibly Create Nested Database Entries from Incoming Pydantic/SQLModels #6https://github.com/fastapi/sqlmodel/issues/6
on Aug 27, 2025https://github.com/fastapi/sqlmodel/issues/224#event-19362900770
Sign up for freehttps://github.com/signup?return_to=https://github.com/fastapi/sqlmodel/issues/224
Sign in to commenthttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/224
investigatehttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22investigate%22
questionFurther information is requestedhttps://github.com/fastapi/sqlmodel/issues?q=state%3Aopen%20label%3A%22question%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.