First Check
Commit to Help
Example Code
class UpsertByModelMixin(SQLModel):
created_by_id : Optional[int] = Field(default=None, foreign_key="users.id")
created_by: Optional["User"] = Relationship(sa_relationship_kwargs={ 'foreign_keys': [created_by_id] })
updated_by_id : Optional[int] = Field(default=None, foreign_key="users.id")
updated_by: Optional["User"] = Relationship(sa_relationship_kwargs={ 'foreign_keys': [updated_by_id] })
class Team(UpsertByModelMixin, SQLModel, table=True,):
__tablename__ = 'teams'
id: Optional[int] = Field(default=None, primary_key=True)
name: str = Field(max_length=500)
### Description
Use models such as above will result in the following error because the `foreign_keys` argument expects a `Column` (not a SQLModel `Field`).
| sqlalchemy.exc.ArgumentError: Column expression expected for argument 'foreign_keys'; got FieldInfo(default=PydanticUndefined, extra={'exclude': None, 'include': None}).
As such, its impossible right now for anyone to deploy classes with multiple FKs to the same identity and/or use custom named foreign key columns.
### Wanted Solution
To be able to specify foreign keys to the same related entity and/or name my fk columns however I choose.
### Wanted Code
```python
Just like above
Alternatives
No response
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.5
Additional Context
No response
First Check
Commit to Help
Example Code
| sqlalchemy.exc.ArgumentError: Column expression expected for argument 'foreign_keys'; got FieldInfo(default=PydanticUndefined, extra={'exclude': None, 'include': None}).
Alternatives
No response
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.4
Python Version
3.9.5
Additional Context
No response