Mike Bayer avatar Mike Bayer committed 91f78a8

- [ticket:768] dont assume join criterion consists only of column objects

Comments (0)

Files changed (3)

     - tweak DISTINCT precedence for clauses like
       `func.count(t.c.col.distinct())`
     - Fixed detection of internal '$' characters in :bind$params [ticket:719]
+    - [ticket:768] dont assume join criterion consists only of column objects
+    
 - 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 

lib/sqlalchemy/sql.py

     encodedname = property(lambda s: s.name.encode('ascii', 'backslashreplace'))
 
     def _init_primary_key(self):
+        from sqlalchemy import schema
         pkcol = util.Set([c for c in self._adjusted_exportable_columns() if c.primary_key])
     
         equivs = {}
                     
         class BinaryVisitor(ClauseVisitor):
             def visit_binary(self, binary):
-                if binary.operator == '=':
+                if binary.operator == '=' and isinstance(binary.left, schema.Column) and isinstance(binary.right, schema.Column):
                     add_equiv(binary.left, binary.right)
         BinaryVisitor().traverse(self.onclause)
         

test/sql/selectable.py

         j.foreign_keys
         assert list(j.primary_key) == [a.c.id]
 
+    def test_non_column_clause(self):
+        meta = MetaData()
+        a = Table('a', meta, Column('id', Integer, primary_key=True), Column('x', Integer))
+        b = Table('b', meta, Column('id', Integer, ForeignKey('a.id'), primary_key=True), Column('x', Integer, primary_key=True))
+
+        j = a.join(b, and_(a.c.id==b.c.id, b.c.x==5))
+        assert str(j) == "a JOIN b ON a.id = b.id AND b.x = :b_x", str(j)
+        assert list(j.primary_key) == [a.c.id, b.c.x]
+
         
         
 if __name__ == "__main__":
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.