]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- The mapper argument "primary_key" can be passed as a
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Nov 2010 17:33:25 +0000 (12:33 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Nov 2010 17:33:25 +0000 (12:33 -0500)
single column as well as a list or tuple.  [ticket:1971]

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

diff --git a/CHANGES b/CHANGES
index d29175e6b3f5054b72156b4fa11ab9cbc3ea02f6..dbc588ac7a859321844940031d329d835705b326 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -28,6 +28,11 @@ CHANGES
     transformed to the empty slice -1:0 that resulted in
     IndexError. [ticket:1968]
 
+  - The mapper argument "primary_key" can be passed as a 
+    single column as well as a list or tuple.  [ticket:1971]
+    The documentation examples that illustrated it as a 
+    scalar value have been changed to lists.  
+    
 - sql
   - The 'info' attribute of Column is copied during 
     Column.copy(), i.e. as occurs when using columns
index e9da4f5337fc3c82461c26f0237852b82ef32bc9..c1045226cdca2ca86dacf58f5b2cfccc1241edf1 100644 (file)
@@ -107,7 +107,7 @@ class Mapper(object):
 
         self.class_manager = None
 
-        self.primary_key_argument = primary_key
+        self.primary_key_argument = util.to_list(primary_key)
         self.non_primary = non_primary
 
         if order_by is not False:
index f041c8896bdf39719cd307b441d6dd7c8865f9cf..52714eb43e197d726bea1ceba92e901bf62b8ede 100644 (file)
@@ -664,6 +664,17 @@ class MapperTest(_fixtures.FixtureTest):
             User(id=9, address_id=5),
             None])
 
+    @testing.resolve_artifact_names
+    def test_scalar_pk_arg(self):
+        m1 = mapper(Item, items, primary_key=[items.c.id])
+        m2 = mapper(Keyword, keywords, primary_key=keywords.c.id)
+        m3 = mapper(User, users, primary_key=(users.c.id,))
+        
+        assert m1.primary_key[0] is items.c.id
+        assert m2.primary_key[0] is keywords.c.id
+        assert m3.primary_key[0] is users.c.id
+        
+        
     @testing.resolve_artifact_names
     def test_custom_join(self):
         """select_from totally replace the FROM parameters."""