[Sqlalchemy-tickets] Issue #3243: ForeignKeyConstraint.columns - WAT (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2014-11-08 21:56:31
|
New issue 3243: ForeignKeyConstraint.columns - WAT https://bitbucket.org/zzzeek/sqlalchemy/issue/3243/foreignkeyconstraintcolumns-wat Mike Bayer: The ".columns" collection is first off not a ColumnCollection, and secondly it is a list that is either of strings or columns, depending on factors that are in a practical sense arbitrary, which is ridiculous. This collection should either not be there at all, or just changed to be a ColumnCollection. Hitting it will just invoke the FK. Some other accessor should be added that gives us the column names in the absense of the FK constraint actually being set up. ``` #!python from sqlalchemy import Integer, Column, Table, MetaData, \ ForeignKeyConstraint, ForeignKey m = MetaData() t1 = Table( 't1', m, Column('x', Integer, primary_key=True) ) t2 = Table( 't2', m, Column('y', Integer, primary_key=True), Column('z1', Integer, ForeignKey('t1.x')), Column('z2', Integer) ) fk1 = [ const for const in t2.constraints if isinstance(const, ForeignKeyConstraint)][0] fk2 = ForeignKeyConstraint(['z2'], ['t1.x']) # keys are Column objects, OK assert isinstance(fk1.columns[0], Column) # WAT assert isinstance(fk2.columns[0], str) t2.append_constraint(fk2) # WAT assert isinstance(fk2.columns[0], str) ``` |