From: Mike Bayer Date: Thu, 18 Nov 2010 17:33:25 +0000 (-0500) Subject: - The mapper argument "primary_key" can be passed as a X-Git-Tag: rel_0_7b1~262 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0825795364af2973dd9b7ce5f40988dccb16a9b8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - The mapper argument "primary_key" can be passed as a single column as well as a list or tuple. [ticket:1971] --- diff --git a/CHANGES b/CHANGES index d29175e6b3..dbc588ac7a 100644 --- 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 diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index e9da4f5337..c1045226cd 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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: diff --git a/test/orm/test_mapper.py b/test/orm/test_mapper.py index f041c8896b..52714eb43e 100644 --- a/test/orm/test_mapper.py +++ b/test/orm/test_mapper.py @@ -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."""