]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
starting to refactor adaptation of inherited properties out of the MapperProperty...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 20 Jan 2007 13:38:50 +0000 (13:38 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 20 Jan 2007 13:38:50 +0000 (13:38 +0000)
lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/orm/mapper.py

index 834f18e281e16b045df1a29797484f2dc2074e6e..959c9c36b31904c8108daaa954e7005f1c9ac051 100644 (file)
@@ -37,10 +37,6 @@ class MapperProperty(object):
         mappers, establish instrumented class attributes"""
         self.key = key
         self.do_init()
-    def adapt_to_inherited(self, key, newparent):
-        """adapt this MapperProperty to a new parent, assuming the new parent is an inheriting
-        descendant of the old parent.  """
-        newparent._compile_property(key, self, init=False, setparent=False)
     def do_init(self):
         """template method for subclasses"""
         pass
index 8efd70967edeceabdc30291e10a98149c8def1a4..1974fdac782c60652ece82230fcd0c137fd607f3 100644 (file)
@@ -462,8 +462,8 @@ class Mapper(object):
 
         if self.inherits is not None:
             for key, prop in self.inherits.__props.iteritems():
-                if not self.__props.has_key(key) and (not self.concrete or not isinstance(prop, ColumnProperty)):
-                    prop.adapt_to_inherited(key, self)
+                if not self.__props.has_key(key):
+                    self._adapt_inherited_property(key, prop)
 
         # load properties from the main table object,
         # not overriding those set up in the 'properties' argument
@@ -665,6 +665,11 @@ class Mapper(object):
         else:
             return None
 
+    def _adapt_inherited_property(self, key, prop):
+        if not self.concrete:
+            self._compile_property(key, prop, init=False, setparent=False)
+        # TODO: concrete properties dont adapt at all right now....will require copies of relations() etc.
+        
     def _compile_property(self, key, prop, init=True, skipmissing=False, setparent=True):
         """add a MapperProperty to this or another Mapper, including configuration of the property.
         
@@ -685,9 +690,7 @@ class Mapper(object):
             prop.set_parent(self)
             
         if isinstance(prop, ColumnProperty):
-            col = self.select_table.corresponding_column(prop.columns[0], keys_ok=True, raiseerr=False)
-            if col is None:
-                col = prop.columns[0]
+            col = self.select_table.corresponding_column(prop.columns[0], keys_ok=False, raiseerr=True)
             self.columns[key] = col
             for col in prop.columns:
                 proplist = self.columntoproperty.setdefault(col, [])
@@ -697,7 +700,7 @@ class Mapper(object):
             prop.init(key, self)
 
         for mapper in self._inheriting_mappers:
-            prop.adapt_to_inherited(key, mapper)
+            mapper._adapt_inherited_property(key, prop)
 
     def __str__(self):
         return "Mapper|" + self.class_.__name__ + "|" + (self.entity_name is not None and "/%s" % self.entity_name or "") + (self.local_table and self.local_table.name or str(self.local_table)) + (not self._is_primary_mapper() and "|non-primary" or "")