René's URL Explorer Experiment


Title: Example: Understanding inheritance and relationships between model classes · Issue #488 · fastapi/sqlmodel · GitHub

Open Graph Title: Example: Understanding inheritance and relationships between model classes · Issue #488 · fastapi/sqlmodel

X Title: Example: Understanding inheritance and relationships between model classes · Issue #488 · 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/488

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Example: Understanding inheritance and relationships between model classes","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\nclass Contract(SQLModel):\r\n    \"\"\"A contract defines the business conditions of a project\"\"\"\r\n    title: str = Field(description=\"Short description of the contract.\")\r\n    client: Client = Relationship(\r\n        back_populates=\"contracts\",\r\n    )\r\n    # Contract n:1 Client\r\n    client_id: Optional[int] = Field(\r\n        default=None,\r\n        foreign_key=\"client.id\",\r\n    )\r\n\r\n    currency: str  \r\n    term_of_payment: Optional[int] = Field(\r\n        description=\"How many days after receipt of invoice this invoice is due.\",\r\n        default=31,\r\n    )\r\n\r\n    \r\nclass TimeContract(Contract, table=True):\r\n    \"\"\"A time-based contract with a rate per time unit\"\"\"\r\n    id: Optional[int] = Field(default=None, primary_key=True)\r\n\r\n    rate: condecimal(decimal_places=2) = Field(\r\n        description=\"Rate of remuneration\",\r\n    )\r\n\r\n    unit: TimeUnit = Field(\r\n        description=\"Unit of time tracked. The rate applies to this unit.\",\r\n        sa_column=sqlalchemy.Column(sqlalchemy.Enum(TimeUnit)),\r\n        default=TimeUnit.hour,\r\n    )\r\n\r\nclass WorksContract(Contract, table=True):\r\n    \"\"\"A contract with a fixed price\"\"\"\r\n    id: Optional[int] = Field(default=None, primary_key=True)\r\n    price: condecimal(decimal_places=2) = Field(\r\n        description=\"Price of the contract\",\r\n    )\r\n    deliverable: str = Field(description=\"Description of the deliverable\")\r\n\r\nclass Client(SQLModel, table=True):\r\n    \"\"\"A client the freelancer has contracted with.\"\"\"\r\n\r\n    id: Optional[int] = Field(default=None, primary_key=True)\r\n    name: str\r\n    contracts: List[\"Contract\"] = Relationship(back_populates=\"client\")\r\n```\r\n\r\n\r\n### Description\r\n\r\nI would like to understand inheritance better using the following example:\r\n- There are two types of contracts, a time-based contract with a rate per time unit, and a works contract with a fixed price.\r\n- Every contract is related to a client.\r\n\r\nThe code example is my first attempt at implementing this. However, It is not yet correct:\r\n\r\n```\r\nInvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'mapped class Client-\u003eclient'. Original exception was: When initializing mapper mapped class Client-\u003eclient, expression 'Contract' failed to locate a name ('Contract'). If this is a class name, consider adding this relationship() to the \u003cclass 'tuttle.model.Client'\u003e class after both dependent classes have been defined.\r\n```\r\n\r\nQuestions:\r\n\r\n- Every `Contract` is related to a client. That makes me think `client` should be a member of the `Contract` base class. However, I don't understand how to properly implement the relationship. Is it necessary to move `client` to the table classes (thereby duplicating it)?\r\n- When using inheritance from a model class, can I still `select` from `Contract` (rather than from the different contract types separately)?\r\n\r\n### Operating System\r\n\r\nmacOS, Other\r\n\r\n### Operating System Details\r\n\r\n_No response_\r\n\r\n### SQLModel Version\r\n\r\n0.0.8\r\n\r\n### Python Version\r\n\r\n3.10\r\n\r\n### Additional Context\r\n\r\n_No response_","author":{"url":"https://github.com/clstaudt","@type":"Person","name":"clstaudt"},"datePublished":"2022-11-05T08:48:54.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":13},"url":"https://github.com/488/sqlmodel/issues/488"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:03967edf-5c48-a04d-c92a-8a7bcdf8a441
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9940:12D78F:2D949E4:3E7A4EA:6964E758
html-safe-nonce6d264fa85b344d30d663fe2730f82ee9b497c5593501e2ef54b017ed7ccfab69
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTQwOjEyRDc4RjoyRDk0OUU0OjNFN0E0RUE6Njk2NEU3NTgiLCJ2aXNpdG9yX2lkIjoiMzgxNzQzMjYzODg2MjcxNDcxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac73660945a771d4ba68645c8562fb1cee3c8c8565f4ea3ebf54ce19f3e1e104df
hovercard-subject-tagissue:1436907185
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/488/issue_layout
twitter:imagehttps://opengraph.githubassets.com/785eb2700869614ab1bd35bc8c6b62563cb1c2de07180e4ca8276a3e0dc51f75/fastapi/sqlmodel/issues/488
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/785eb2700869614ab1bd35bc8c6b62563cb1c2de07180e4ca8276a3e0dc51f75/fastapi/sqlmodel/issues/488
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:usernameclstaudt
hostnamegithub.com
expected-hostnamegithub.com
None3c30097417ecb9dfdab6b2e8bc7dc38d73e183d6ad48f94cb69e4a5daa2dbb87
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
release69fc54a84c74307369dba42af5401200531d116e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/fastapi/sqlmodel/issues/488#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F488
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Ffastapi%2Fsqlmodel%2Fissues%2F488
Sign up https://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/488
Reloadhttps://github.com/fastapi/sqlmodel/issues/488
Reloadhttps://github.com/fastapi/sqlmodel/issues/488
fastapi https://github.com/fastapi
sqlmodelhttps://github.com/fastapi/sqlmodel
Please reload this pagehttps://github.com/fastapi/sqlmodel/issues/488
Notifications https://github.com/login?return_to=%2Ffastapi%2Fsqlmodel
Fork 790 https://github.com/login?return_to=%2Ffastapi%2Fsqlmodel
Star 17.5k https://github.com/login?return_to=%2Ffastapi%2Fsqlmodel
Code https://github.com/fastapi/sqlmodel
Issues 60 https://github.com/fastapi/sqlmodel/issues
Pull requests 51 https://github.com/fastapi/sqlmodel/pulls
Discussions https://github.com/fastapi/sqlmodel/discussions
Actions https://github.com/fastapi/sqlmodel/actions
Projects 0 https://github.com/fastapi/sqlmodel/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/fastapi/sqlmodel/security
Please reload this pagehttps://github.com/fastapi/sqlmodel/issues/488
Insights https://github.com/fastapi/sqlmodel/pulse
Code https://github.com/fastapi/sqlmodel
Issues https://github.com/fastapi/sqlmodel/issues
Pull requests https://github.com/fastapi/sqlmodel/pulls
Discussions https://github.com/fastapi/sqlmodel/discussions
Actions https://github.com/fastapi/sqlmodel/actions
Projects https://github.com/fastapi/sqlmodel/projects
Security https://github.com/fastapi/sqlmodel/security
Insights https://github.com/fastapi/sqlmodel/pulse
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/488
New issuehttps://github.com/login?return_to=https://github.com/fastapi/sqlmodel/issues/488
Example: Understanding inheritance and relationships between model classeshttps://github.com/fastapi/sqlmodel/issues/488#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/clstaudt
https://github.com/clstaudt
clstaudthttps://github.com/clstaudt
on Nov 5, 2022https://github.com/fastapi/sqlmodel/issues/488#issue-1436907185
Pydantichttps://github.com/samuelcolvin/pydantic
SQLAlchemyhttps://github.com/sqlalchemy/sqlalchemy
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.