]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- a warning is issued by Mapper when two primary key columns of the
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 13 Jul 2007 08:12:30 +0000 (08:12 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 13 Jul 2007 08:12:30 +0000 (08:12 +0000)
same name are munged into a single attribute.  this happens frequently
when mapping to joins (or inheritance).

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

diff --git a/CHANGES b/CHANGES
index bd71fe1b1fbca32dfb574e0af99cd48b0431b130..94a925cae67cf97d3204ad5f67c1ed682d7f29c7 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -25,6 +25,9 @@
     - added synchronization to the mapper() construction step, to avoid
       thread collections when pre-existing mappers are compiling in a 
       different thread [ticket:613]
+    - a warning is issued by Mapper when two primary key columns of the
+      same name are munged into a single attribute.  this happens frequently
+      when mapping to joins (or inheritance). 
     - synonym() properties are fully supported by all Query joining/
       with_parent operations [ticket:598]
     - fixed very stupid bug when deleting items with many-to-many
index bd5e07b148f2a5133573dfa90517d3f96382e2a6..375408926fb897d958ee105e37414327f9d11de2 100644 (file)
@@ -9,7 +9,7 @@ from sqlalchemy import sql_util as sqlutil
 from sqlalchemy.orm import util as mapperutil
 from sqlalchemy.orm import sync
 from sqlalchemy.orm.interfaces import MapperProperty, MapperOption, OperationContext, SynonymProperty
-import weakref
+import weakref, warnings
 
 __all__ = ['Mapper', 'MapperExtension', 'class_mapper', 'object_mapper', 'EXT_PASS', 'mapper_registry', 'ExtensionOption']
 
@@ -585,6 +585,8 @@ class Mapper(object):
                     prop = ColumnProperty(deferred=prop.deferred, group=prop.group, *prop.columns)
                     prop.set_parent(self)
                     self.__props[column_key] = prop
+                if column in self.primary_key and prop.columns[-1] in self.primary_key:
+                    warnings.warn(RuntimeWarning("On mapper %s, primary key column '%s' is being combined with distinct primary key column '%s' in attribute '%s'.  Use explicit properties to give each column its own mapped attribute name." % (str(self), str(column), str(prop.columns[-1]), column_key)))
                 prop.columns.append(column)
                 self.__log("appending to existing ColumnProperty %s" % (column_key))
             else:
index 8d12250887f74acac38c4392bb010c42c1d9f6d1..0458716e5aa1d17aba2b8161648246cd25e3f6ce 100644 (file)
@@ -427,7 +427,7 @@ class InheritTest7(testbase.ORMTest):
                 'roles' : relation(Role, secondary=user_roles, lazy=False, private=False) 
             }
         )
-        admin_mapper = mapper(Admin, admins, inherits=user_mapper)
+        admin_mapper = mapper(Admin, admins, inherits=user_mapper, properties={'aid':admins.c.id})
         sess = create_session()
         adminrole = Role('admin')
         sess.save(adminrole)
@@ -463,7 +463,7 @@ class InheritTest7(testbase.ORMTest):
             }
         )
 
-        admin_mapper = mapper(Admin, admins, inherits=user_mapper) 
+        admin_mapper = mapper(Admin, admins, inherits=user_mapper, properties={'aid':admins.c.id}
 
         # create roles
         adminrole = Role('admin')
index 6f652e692e72899ce9400e18e91b37676e0a340a..7c9bbc8987ec77488782321119d5813429249abe 100644 (file)
@@ -559,19 +559,19 @@ class TypeMatchTest(testbase.ORMTest):
     def define_tables(self, metadata):
         global a, b, c, d
         a = Table("a", metadata, 
-            Column('id', Integer, primary_key=True),
+            Column('aid', Integer, primary_key=True),
             Column('data', String(30)))
         b = Table("b", metadata, 
-            Column('id', Integer, primary_key=True),
-            Column("a_id", Integer, ForeignKey("a.id")),
+            Column('bid', Integer, primary_key=True),
+            Column("a_id", Integer, ForeignKey("a.aid")),
             Column('data', String(30)))
         c = Table("c", metadata, 
-            Column('id', Integer, primary_key=True),
-            Column("b_id", Integer, ForeignKey("b.id")),
+            Column('cid', Integer, primary_key=True),
+            Column("b_id", Integer, ForeignKey("b.bid")),
             Column('data', String(30)))
         d = Table("d", metadata, 
-            Column('id', Integer, primary_key=True),
-            Column("a_id", Integer, ForeignKey("a.id")),
+            Column('did', Integer, primary_key=True),
+            Column("a_id", Integer, ForeignKey("a.aid")),
             Column('data', String(30)))
     def test_o2m_oncascade(self):
         class A(object):pass