Skip to content

Commit

Permalink
added foreign_key_kwargs to Field
Browse files Browse the repository at this point in the history
  • Loading branch information
thedamnedrhino committed Jun 20, 2023
1 parent 43a689d commit ca9dc4c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sqlmodel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def __init__(self, default: Any = Undefined, **kwargs: Any) -> None:
primary_key = kwargs.pop("primary_key", False)
nullable = kwargs.pop("nullable", Undefined)
foreign_key = kwargs.pop("foreign_key", Undefined)
foreign_key_kwargs = kwargs.pop("foreign_key_kwargs", Undefined)
unique = kwargs.pop("unique", False)
index = kwargs.pop("index", Undefined)
sa_column = kwargs.pop("sa_column", Undefined)
Expand All @@ -81,6 +82,7 @@ def __init__(self, default: Any = Undefined, **kwargs: Any) -> None:
self.primary_key = primary_key
self.nullable = nullable
self.foreign_key = foreign_key
self.foreign_key_kwargs = foreign_key_kwargs
self.unique = unique
self.index = index
self.sa_column = sa_column
Expand Down Expand Up @@ -143,6 +145,7 @@ def Field(
regex: Optional[str] = None,
primary_key: bool = False,
foreign_key: Optional[Any] = None,
foreign_key_kwargs: Optional[Mapping[str, Any]] = None,
unique: bool = False,
nullable: Union[bool, UndefinedType] = Undefined,
index: Union[bool, UndefinedType] = Undefined,
Expand Down Expand Up @@ -174,6 +177,7 @@ def Field(
regex=regex,
primary_key=primary_key,
foreign_key=foreign_key,
foreign_key_kwargs=foreign_key_kwargs,
unique=unique,
nullable=nullable,
index=index,
Expand Down Expand Up @@ -432,9 +436,10 @@ def get_column_from_field(field: ModelField) -> Column: # type: ignore
nullable = field_nullable
args = []
foreign_key = getattr(field.field_info, "foreign_key", None)
foreign_key_kwargs = getattr(field.field_info, "foreign_key_kwargs", None)
unique = getattr(field.field_info, "unique", False)
if foreign_key:
args.append(ForeignKey(foreign_key))
args.append(ForeignKey(foreign_key, **(foreign_key_kwargs or dict())))
kwargs = {
"primary_key": primary_key,
"nullable": nullable,
Expand Down

0 comments on commit ca9dc4c

Please sign in to comment.