]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added a check for joining from A->B using join(), along two
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 26 Jul 2007 18:25:50 +0000 (18:25 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 26 Jul 2007 18:25:50 +0000 (18:25 +0000)
      different m2m tables.  this raises an error in 0.3 but is
      possible in 0.4 when aliases are used. [ticket:687]

CHANGES
lib/sqlalchemy/orm/query.py
setup.py
test/orm/query.py

diff --git a/CHANGES b/CHANGES
index c4dcf467622146086ce0d20025ad5a98791669d9..9d75e2dfbdd5aae837ecf71fd8c8bca88ef79363 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,12 @@
+0.3.11
+- orm
+    - added a check for joining from A->B using join(), along two
+      different m2m tables.  this raises an error in 0.3 but is 
+      possible in 0.4 when aliases are used. [ticket:687]
+- mssql
+    - added support for TIME columns (simulated using DATETIME) [ticket:679]
+    - index names are now quoted when dropping from reflected tables [ticket:684]
+      
 0.3.10
 - general
     - a new mutex that was added in 0.3.9 causes the pool_timeout
@@ -19,9 +28,6 @@
 - postgres
     - fixed max identifier length (63) [ticket:571]
 
-- mssql
-    - added support for TIME columns (simulated using DATETIME) [ticket:679]
-    - index names are now quoted when dropping from reflected tables [ticket:684]
 
 0.3.9
 - general
index 02deebdca953cb24d7724a4bd29b1cb8cdf4ecbf..d51fd75c38f458897d0223ee024b0a0860be9282 100644 (file)
@@ -614,7 +614,13 @@ class Query(object):
                         clause = clause.join(prop.select_table, prop.get_join(mapper, primary=False))
                     else:
                         clause = clause.join(prop.select_table, prop.get_join(mapper))
+            elif prop.secondary is not None and prop.secondary not in currenttables:
+                # TODO: this check is not strong enough for different paths to the same endpoint which
+                # does not use secondary tables
+                raise exceptions.InvalidRequestError("Can't join to property '%s'; a path to this table along a different secondary table already exists.  Use explicit `Alias` objects." % prop.key)
+                
             mapper = prop.mapper
+            
         return (clause, mapper)
 
     def _join_by(self, args, params, start=None):
index 38b004be224157654517415d563879ce767fe58c..092d0d50858104af1b27b1a2eaa66844fa0b71c8 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -3,7 +3,7 @@ use_setuptools()
 from setuptools import setup, find_packages
 
 setup(name = "SQLAlchemy",
-    version = "0.3.10",
+    version = "0.3.11",
     description = "Database Abstraction Library",
     author = "Mike Bayer",
     author_email = "mike_mp@zzzcomputing.com",
index 22b9d8e117f84c7882044018f8cee1bae3ea2830..872d1772e4c4bcd55749d21db0886935aac79374 100644 (file)
@@ -206,7 +206,44 @@ class JoinTest(QueryTest):
         result = create_session().query(User).select_from(users.join(oalias)).filter(oalias.c.description.in_("order 1", "order 2", "order 3")).join(['orders', 'items']).filter_by(id=4).all()
         assert [User(id=7, name='jack')] == result
 
-
+class MultiplePathTest(testbase.ORMTest):
+    def define_tables(self, metadata):
+        global t1, t2, t1t2_1, t1t2_2
+        t1 = Table('t1', metadata,
+            Column('id', Integer, primary_key=True),
+            Column('data', String(30))
+            )
+        t2 = Table('t2', metadata,
+            Column('id', Integer, primary_key=True),
+            Column('data', String(30))
+            )
+            
+        t1t2_1 = Table('t1t2_1', metadata,
+            Column('t1id', Integer, ForeignKey('t1.id')),
+            Column('t2id', Integer, ForeignKey('t2.id'))
+            )
+
+        t1t2_2 = Table('t1t2_2', metadata,
+            Column('t1id', Integer, ForeignKey('t1.id')),
+            Column('t2id', Integer, ForeignKey('t2.id'))
+            )
+            
+    def test_basic(self):
+        class T1(object):pass
+        class T2(object):pass
+        
+        mapper(T1, t1, properties={
+            't2s_1':relation(T2, secondary=t1t2_1),
+            't2s_2':relation(T2, secondary=t1t2_2),
+        })
+        mapper(T2, t2)
+        
+        try:
+            create_session().query(T1).join('t2s_1').filter_by(t2.c.id==5).reset_joinpoint().join('t2s_2')
+            assert False
+        except exceptions.InvalidRequestError, e:
+            assert str(e) == "Can't join to property 't2s_2'; a path to this table along a different secondary table already exists.  Use explicit `Alias` objects."
+        
 class SynonymTest(QueryTest):
     keep_mappers = True
     keep_data = True