Re: [Sqlalchemy-tickets] [sqlalchemy] #2738: SQLAlchemy should throw an exception if there are mult
Brought to you by:
zzzeek
|
From: sqlalchemy <mi...@zz...> - 2013-06-02 00:09:50
|
#2738: SQLAlchemy should throw an exception if there are multiple foreign keys to
relate
----------------------------+----------------------------------
Reporter: Svenstaro | Owner: zzzeek
Type: defect | Status: new
Priority: high | Milestone: 0.8.xx
Component: schema | Severity: minor - half an hour
Resolution: | Keywords:
Progress State: in queue |
----------------------------+----------------------------------
Changes (by zzzeek):
* priority: medium => high
* status_field: awaiting triage => in queue
* component: cextensions => schema
* severity: no triage selected yet => minor - half an hour
* milestone: => 0.8.xx
Comment:
yeah wow, weird how nobody finds these for so long.
Here's that:
{{{
#!python
from sqlalchemy import *
m = MetaData()
t1 = Table('t', m,
Column('id', Integer, primary_key=True)
)
t2 = Table('t2', m,
Column('id1', ForeignKey('t.id')),
Column('id2', ForeignKey('t.id')),
)
s = select([t2]).alias()
print t1.join(s)
}}}
here's the patch:
{{{
#!diff
index 3a74cbd..1febb1b 100644
--- a/lib/sqlalchemy/schema.py
+++ b/lib/sqlalchemy/schema.py
@@ -1134,7 +1134,9 @@ class Column(SchemaItem, expression.ColumnClause):
information is not transferred.
"""
- fk = [ForeignKey(f.column) for f in self.foreign_keys]
+
+ fk = [ForeignKey(f.column, _constraint=f.constraint)
+ for f in self.foreign_keys]
if name is None and self.name is None:
raise exc.InvalidRequestError("Cannot initialize a sub-
selectable"
" with this Column object until it's 'name' has "
}}}
need to also test `print id(fk.constraint.elements[0])`, etc. should go
into test_selectable.
--
Ticket URL: <http://www.sqlalchemy.org/trac/ticket/2738#comment:1>
sqlalchemy <http://www.sqlalchemy.org/>
The Database Toolkit for Python
|