]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fix to the "column_prefix" flag so that the mapper does not
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Jun 2007 20:38:43 +0000 (20:38 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 27 Jun 2007 20:38:43 +0000 (20:38 +0000)
trip over synonyms (and others) that are named after the column's actual
"key" (since, column_prefix means "dont use the key").

CHANGES
lib/sqlalchemy/orm/mapper.py
test/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 0b17de8d7ba39e8f08839782b4a228893e6609c0..c77f76318cafc983c395392ca34c3070ab5ca61d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -25,6 +25,9 @@
     - small fix to eager loading to better work with eager loads
       to polymorphic mappers that are using a straight "outerjoin"
       clause
+    - fix to the "column_prefix" flag so that the mapper does not 
+      trip over synonyms (and others) that are named after the column's actual
+      "key" (since, column_prefix means "dont use the key").
 - sql
     - fixed grouping of compound selects to give correct results. will break
       on sqlite in some cases, but those cases were producing incorrect
index 994264cc7987ed8f0eb72839cbd864d2a00ebabf..461b9da7ab8f280dbd2ea93f8a23ac15c2ce53f7 100644 (file)
@@ -555,7 +555,7 @@ class Mapper(object):
                 self.columns[column.key] = self.select_table.corresponding_column(column, keys_ok=True, raiseerr=True)
 
             column_key = (self.column_prefix or '') + column.key
-            prop = self.__props.get(column.key, None)
+            prop = self.__props.get(column_key, None)
             if prop is None:
                 prop = ColumnProperty(column)
                 self.__props[column_key] = prop
index a8beabf6d32927f9d4caab6b3aefd53bb02a830b..399b87e33095a518a551433ecb0ecf99408270a9 100644 (file)
@@ -76,12 +76,16 @@ class MapperTest(MapperSuperTest):
             assert str(e) == "Invalid cascade option 'fake'"
         
     def testcolumnprefix(self):
-        mapper(User, users, column_prefix='_')
+        mapper(User, users, column_prefix='_', properties={
+            'user_name':synonym('_user_name')
+        })
         s = create_session()
         u = s.get(User, 7)
         assert u._user_name=='jack'
        assert u._user_id ==7
         assert not hasattr(u, 'user_name')
+        u2 = s.query(User).filter_by(user_name='jack').one()
+        assert u is u2
           
     def testrefresh(self):
         mapper(User, users, properties={'addresses':relation(mapper(Address, addresses))})