foreign_key
FkParams
Bases: NamedTuple
Parameters of a relation field derived from the model it leads to.
Attributes:
| Name | Type | Description |
|---|---|---|
annotation |
Any
|
pydantic type of the field |
column_type |
Any
|
SQLAlchemy type of the referencing column |
key_only_model |
type[BaseModel]
|
pydantic model validating key-only values |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
40 41 42 43 44 45 46 47 48 49 50 51 | |
ForeignKeyField
Bases: BaseField
Actual class returned from ForeignKey function call and stored in model_fields.
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 | |
kind
property
Returns:
| Type | Description |
|---|---|
RelationKind
|
forward or reverse side of a foreign key or one-to-one relation |
link
property
Columns connecting the owner's table to the table of the related model, built once per owner and target: a field copied to another model (inheritance) or re-targeted (forward refs) builds its own link.
Returns:
| Type | Description |
|---|---|
RelationLink
|
link from the owner to the related model |
build_link()
A foreign key links its own column to the target's primary key, a reverse relation is the mirror of the foreign key it was created from.
Returns:
| Type | Description |
|---|---|
RelationLink
|
link from the owner to the related model |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |
column_aliases()
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
the owner's column names of the foreign key |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
745 746 747 748 749 750 751 752 | |
construct_constraints()
Build the SQLAlchemy foreign keys of the field's column from its link,
one per column pair, named foreign_key_name or
fk_<owner table>_<target table>_<target column>_<field name>.
Built on every call, as SQLAlchemy binds a ForeignKey to one table and
subclasses need their own.
Returns:
| Type | Description |
|---|---|
list
|
SQLAlchemy foreign keys, empty until the target is resolved |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 | |
construct_key_only_model(value)
Takes a key value and creates an instance of the related model with only the key populated, without registering it on any side.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
value of a related pk / fk column |
required |
Returns:
| Type | Description |
|---|---|
Model
|
related model with only pk set |
Raises:
| Type | Description |
|---|---|
RelationshipInstanceError
|
if value does not match the pk type |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 | |
construct_table_constraints()
Returns:
| Type | Description |
|---|---|
list
|
the table-level items of a foreign key of several columns:
its |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 | |
default_source_field_name()
Returns default target model name on through model.
Returns:
| Type | Description |
|---|---|
str
|
name of the field |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
634 635 636 637 638 639 640 641 | |
default_target_field_name()
Returns default target model name on through model.
Returns:
| Type | Description |
|---|---|
str
|
name of the field |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
625 626 627 628 629 630 631 632 | |
evaluate_forward_ref(globalns, localns)
Evaluates the ForwardRef to actual Field based on global and local namespaces
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
globalns
|
Any
|
global namespace |
required |
localns
|
Any
|
local namespace |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 | |
expand_relationship(value, child, to_register=True)
For relations the child model is first constructed (if needed), registered in relation and returned. For relation fields the value can be a pk value (Any type of field), dict (from Model) or actual instance/list of a "Model".
Selects the appropriate constructor based on a passed value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
a Model field value, returned untouched for non relation fields. |
required |
child
|
Union[Model, NewBaseModel]
|
a child Model to register |
required |
to_register
|
bool
|
flag if the relation should be set in RelationshipManager |
True
|
Returns:
| Type | Description |
|---|---|
Optional[Union["Model", list["Model"]]]
|
returns a Model or a list of Models |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 | |
flat_columns()
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
columns of the related model holding |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1011 1012 1013 1014 1015 1016 1017 1018 | |
flat_fields()
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
fields of a related model that represent it in flattened output: the referenced fields of a foreign key, the primary key of a reverse or many-to-many relation |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
976 977 978 979 980 981 982 983 984 985 | |
flat_from_columns(values)
Build the flattened representation of a related model (see
flat_value) out of the values of its flat_columns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
dict[str, Any]
|
values of the related model's columns by column name |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the referenced value, a dict of them for several fields |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 | |
flat_value(related)
Represent a related model in flattened output (flatten_fields)::
| Text Only | |
|---|---|
1 2 3 4 | |
A referenced field that is itself a relation (a key holding a foreign key) is represented by its own flattened value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
related
|
Model
|
related model |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the referenced value, a dict of them for several fields |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 | |
flat_value_type()
Returns:
| Type | Description |
|---|---|
Any
|
python type of a flattened related model (see |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1037 1038 1039 1040 1041 1042 1043 1044 1045 | |
get_columns()
Returns:
| Type | Description |
|---|---|
list[sqlalchemy.Column]
|
the owner's columns of the foreign key, one per referenced column (a placeholder single column until a forward reference is resolved) |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 | |
get_related_name()
Returns name to use for reverse relation.
It's either set as related_name or by default it's owner model. get_name + 's'
Returns:
| Type | Description |
|---|---|
str
|
name of the related_name or default related name. |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
615 616 617 618 619 620 621 622 623 | |
get_relation_name()
Returns name of the relation, which can be a own name or through model names for m2m models
Returns:
| Type | Description |
|---|---|
bool
|
result of the check |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1154 1155 1156 1157 1158 1159 1160 1161 1162 | |
has_unresolved_forward_refs()
Verifies if the filed has any ForwardRefs that require updating before the model can be used.
Returns:
| Type | Description |
|---|---|
bool
|
result of the check |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1087 1088 1089 1090 1091 1092 1093 1094 1095 | |
local_column(target_column, several)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_column
|
str
|
referenced column of the related model's table |
required |
several
|
bool
|
whether the foreign key references several columns |
required |
Returns:
| Type | Description |
|---|---|
str
|
name of the owner's column storing it: from |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
register_relation(model, child)
Registers relation between parent and child in relation manager. Relation manager is kep on each model (different instance).
Used in Metaclass and sometimes some relations are missing (i.e. cloned Models in fastapi might miss one).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Model
|
parent model (with relation definition) |
required |
child
|
Model
|
child model |
required |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 | |
target_fields()
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
fields of the related model the foreign key references: its
|
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
692 693 694 695 696 697 698 699 700 701 | |
target_value_of(related)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
related
|
Any
|
related model, its key-only model, a dict of its fields or a raw value |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the value this foreign key stores for it, |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
965 966 967 968 969 970 971 972 973 974 | |
target_value_type()
Returns:
| Type | Description |
|---|---|
Any
|
python type of a raw value of the relation: the |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
target_values(value)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Any
|
raw value of the relation |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
the value split into the referenced fields of the related model |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
ForeignKey(to, *, name=None, unique=False, nullable=None, related_name=None, virtual=False, onupdate=None, ondelete=None, foreign_key_name=None, **kwargs)
ForeignKey(to: type[T], **kwargs: Any) -> T
ForeignKey(to: ForwardRef, **kwargs: Any) -> Model
Despite a name it's a function that returns constructed ForeignKeyField. This function is actually used in model declaration (as ormar.ForeignKey(ToModel)).
Accepts number of relation setting parameters as well as all BaseField ones.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
Union[type[T], ForwardRef]
|
target related ormar Model |
required |
name
|
Optional[str]
|
name of the database field - later called alias |
None
|
unique
|
bool
|
parameter passed to sqlalchemy.ForeignKey, unique flag |
False
|
nullable
|
Optional[bool]
|
marks field as optional/ required; defaults to optional, and to required for a foreign key in the primary key |
None
|
related_name
|
Optional[str]
|
name of reversed FK relation populated for you on to model |
None
|
virtual
|
bool
|
marks if relation is virtual. It is for reversed FK and auto generated FK on through model in Many2Many relations. |
False
|
onupdate
|
Union[ReferentialAction, str, None]
|
parameter passed to sqlalchemy.ForeignKey. How to treat child rows on update of parent (the one where FK is defined) model. |
None
|
ondelete
|
Union[ReferentialAction, str, None]
|
parameter passed to sqlalchemy.ForeignKey. How to treat child rows on delete of parent (the one where FK is defined) model. |
None
|
foreign_key_name
|
Optional[str]
|
optional override for the foreign key constraint name generated in migrations. Useful when the auto-generated name exceeds a database specific identifier length limit (for example MySQL 64 chars). |
None
|
kwargs
|
Any
|
all other args to be populated by BaseField |
{}
|
Returns:
| Type | Description |
|---|---|
ForeignKeyField
|
ormar ForeignKeyField with relation to selected model |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
OneToOne(to, **kwargs)
OneToOne(to: type[T], **kwargs: Any) -> T
OneToOne(to: ForwardRef, **kwargs: Any) -> Model
A foreign key whose related model has at most one model pointing back at it:
its column is unique (unless it is the primary key, which already is), and
the reverse side holds a single model or None instead of a list. The
default reverse name is the owner model name, without the trailing s.
Accepts the same arguments as ForeignKey.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
Union[type[T], ForwardRef]
|
target related ormar Model |
required |
kwargs
|
Any
|
|
{}
|
Returns:
| Type | Description |
|---|---|
ForeignKeyField
|
ormar ForeignKeyField with a one to one relation |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 | |
column_type(model, field, column)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[Model]
|
model the column belongs to |
required |
field
|
str
|
field of the model storing the column |
required |
column
|
str
|
database column |
required |
Returns:
| Type | Description |
|---|---|
Any
|
SQLAlchemy type of the column: the field's own type, the type of the referenced column for a foreign key |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
flat_field_from_columns(model, field, values)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[Model]
|
model the field belongs to |
required |
field
|
str
|
referenced field |
required |
values
|
dict[str, Any]
|
values of the model's columns by column name |
required |
Returns:
| Type | Description |
|---|---|
Any
|
the field's value in flattened output: a relation's own
flattened value (see |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
flat_field_type(model, field)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
type[Model]
|
model the field belongs to |
required |
field
|
str
|
referenced field |
required |
Returns:
| Type | Description |
|---|---|
Any
|
python type of the field in flattened output (see
|
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
populate_fk_params_based_on_to_model(*, to, nullable, virtual, to_field=None)
Based on target to model to which relation leads to populates the type of the pydantic field to use and the type of the referencing column.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
type[T]
|
target related ormar Model |
required |
nullable
|
bool
|
marks field as optional/ required |
required |
virtual
|
bool
|
whether the field is a reverse relation holding no column |
required |
to_field
|
Union[str, list[str], tuple[str, ...], None]
|
unique field(s) of the target referenced instead of its pk |
None
|
Returns:
| Type | Description |
|---|---|
FkParams
|
annotation, column type and key-only model of the relation |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 | |
referenced_columns(to, to_field)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
type[Model]
|
target model |
required |
to_field
|
Union[str, list[str], tuple[str, ...], None]
|
referenced field(s), |
required |
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
database columns of the target a foreign key references, each
with the target field storing it: the |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
to_field_names(to_field)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_field
|
Union[str, list[str], tuple[str, ...], None]
|
|
required |
Returns:
| Type | Description |
|---|---|
Optional[tuple[str, ...]]
|
the referenced field names as a tuple, |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
validate_link_columns(to, to_field, columns, name)
Validate the column options of a foreign key against the columns it references.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
type[Model]
|
target model |
required |
to_field
|
Union[str, list[str], tuple[str, ...], None]
|
referenced field(s), |
required |
columns
|
Optional[dict[str, str]]
|
local column names by referenced column |
required |
name
|
Optional[str]
|
single local column name |
required |
Raises:
| Type | Description |
|---|---|
ModelDefinitionError
|
if |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
validate_not_allowed_fields(kwargs)
Verifies if not allowed parameters are set on relation models. Usually they are omitted later anyway but this way it's explicitly notify the user that it's not allowed/ supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kwargs
|
dict
|
dict of kwargs to verify passed to relation field |
required |
Raises:
| Type | Description |
|---|---|
ModelDefinitionError
|
if any forbidden field is set |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
validate_referential_action(action)
Validation onupdate and ondelete action cast to a string value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Optional[Union[ReferentialAction, str]]
|
referential action attribute or name string |
required |
Raises:
| Type | Description |
|---|---|
ModelDefinitionError
|
if action is a not valid name string value |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 | |
validate_to_field(to, fields)
Check that to_field names fields identifying one row of the target: its
primary key, a unique=True field, or exactly the columns of a unique
constraint (UniqueColumns).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
type[Model]
|
target model |
required |
fields
|
tuple[str, ...]
|
referenced field names |
required |
Raises:
| Type | Description |
|---|---|
ModelDefinitionError
|
if a field does not exist or the set is not unique |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
validate_view_target(to, virtual, db_constraint)
A database can't enforce a foreign key to a view, so a relation to a model mapped to a view must not create one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to
|
type[Model]
|
target model |
required |
virtual
|
bool
|
whether the field is a reverse relation holding no column |
required |
db_constraint
|
bool
|
whether the foreign key creates a database constraint |
required |
Raises:
| Type | Description |
|---|---|
ModelDefinitionError
|
if a foreign key to a view keeps its constraint |
Source code in ormar/fields/foreign_key.py
| Python | |
|---|---|
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |