Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sqlalchemy-stubs/sql/schema.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,11 @@ class ForeignKeyConstraint(ColumnCollectionConstraint):
use_alter: bool = ...
match: Optional[str] = ...
elements: List[ForeignKey] = ...
def __init__(self, columns: SequenceType[str], refcolumns: SequenceType[Union[str, Column[Any]]], name: Optional[str] = ...,
onupdate: Optional[str] = ..., ondelete: Optional[str] = ..., deferrable: Optional[bool] = ...,
initially: Optional[str] = ..., use_alter: bool = ..., link_to_name: bool = ..., match: Optional[str] = ...,
table: Optional[Table] = ..., info: Optional[Mapping[str, Any]] = ..., **dialect_kw: Any) -> None: ...
def __init__(self, columns: SequenceType[Union[str, Column[Any]]], refcolumns: SequenceType[Union[str, Column[Any]]],
name: Optional[str] = ..., onupdate: Optional[str] = ..., ondelete: Optional[str] = ...,
deferrable: Optional[bool] = ..., initially: Optional[str] = ..., use_alter: bool = ...,
link_to_name: bool = ..., match: Optional[str] = ..., table: Optional[Table] = ...,
info: Optional[Mapping[str, Any]] = ..., **dialect_kw: Any) -> None: ...
@property
def referred_table(self) -> Table: ...
@property
Expand Down
35 changes: 35 additions & 0 deletions test/test-data/sqlalchemy-sql-schema.test
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,38 @@ test_table = Table('test', metadata,
Index('idx1', 'id', text("lower(name)")),
)
[out]

[case testColumnWithForeignKeyThroughTableArgsAsColumn]
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKeyConstraint, Integer

Base = declarative_base()

class Profile(Base):
__tablename__ = "profile"
id = Column(Integer, primary_key=True)

class User(Base):

__tablename__ = "user"
artkey = Column(Integer, primary_key=True)
profile_id = Column(Integer, nullable=False)
__table_args__ = (ForeignKeyConstraint([profile_id], [Profile.id]), )
[out]

[case testColumnWithForeignKeyThroughTableArgsAsString]
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKeyConstraint, Integer

Base = declarative_base()

class Profile(Base):
__tablename__ = "profile"
id = Column(Integer, primary_key=True)

class User(Base):
__tablename__ = "user"
id = Column(Integer, primary_key=True)
profile_id = Column(Integer, nullable=False)
__table_args__ = (ForeignKeyConstraint(["profile_id"], [Profile.id]), )
[out]