Skip to content

Optional[Department] vs Optional[Union[Department, Dict]] #100

Answered by collerek
Erhannis asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, so I enabled the github discussions as a place for asking questions and discussing changes etc.

The annotations are totally optional and everything will work as expected without them.
The relations fields are actually quite complex and hard to annotate as they behave like this:

You always get in return (for FK field): ormar.Model instance or None

but you can initialize a related model in several ways:

  • with ormar.Model instance (pass Department instance in example above)
  • with dictionary containing keys matching model names
  • with primary key field value (so depends on the type of the primary key column: string, int, uuid etc.) < - so basically Any
  • None

So when you put department: Optio…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Erhannis
Comment options

Answer selected by Erhannis
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #98 on February 16, 2021 08:29.