Skip to content

Commit

Permalink
Fix unique key case
Browse files Browse the repository at this point in the history
  • Loading branch information
adsharma committed Jan 18, 2025
1 parent 7d1ec47 commit ec46455
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fquery/sqlmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


def unique():
pass
return field(default=None, metadata={"SQL": {"unique": True}})


def foreignkey(name):
Expand Down Expand Up @@ -85,11 +85,12 @@ def sqlmodel(self) -> SQLModel:
return self.__sqlmodel__(**attrs)

def get_field_def(cls, field) -> Union[Field, Relationship]:
if field.default == unique:
return Field(unique=True)
sql_meta = field.metadata.get("SQL", {})
has_foreign_key = bool(sql_meta.get("foreign_key", None))
has_relationship = bool(sql_meta.get("relationship", None))
has_unique_constraint = sql_meta.get("unique", False)
if has_unique_constraint:
return Field(unique=True)

if not sql_meta or not (has_foreign_key or has_relationship):
return Field(
Expand Down

0 comments on commit ec46455

Please sign in to comment.