]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- eesh ! the tutorial doctest was broken for quite some time.
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Aug 2006 02:02:47 +0000 (02:02 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 15 Aug 2006 02:02:47 +0000 (02:02 +0000)
- add_property() method on mapper does a "compile all mappers"
step in case the given property references a non-compiled mapper
(as it did in the case of the tutorial !)

CHANGES
doc/build/content/tutorial.txt
lib/sqlalchemy/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 77c8f7b48880500a595fdeafcffff9ffd1772f95..b8320e7b24f1f4e46b54ae33824128686f56ee18 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,9 @@
+0.2.8
+- eesh !  the tutorial doctest was broken for quite some time.
+- add_property() method on mapper does a "compile all mappers"
+step in case the given property references a non-compiled mapper
+(as it did in the case of the tutorial !)
+
 0.2.7
 - quoting facilities set up so that database-specific quoting can be
 turned on for individual table, schema, and column identifiers when
index cd443653ecdf6565274d29fc3c8634175d38ff01..201234e47f22b0f1b02b41afdc0b4620251fb936 100644 (file)
@@ -99,10 +99,11 @@ As you might have guessed, we have just defined a table named `users` which has
     {python}
     >>> metadata.engine.echo = True
     >>> users_table.create() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
-    CREATE TABLE users(
-        user_id INTEGER NOT NULL PRIMARY KEY,
+    CREATE TABLE users (
+        user_id INTEGER NOT NULL,
         user_name VARCHAR(40),
-        password VARCHAR(10)
+        password VARCHAR(10),
+        PRIMARY KEY (user_id)
     )
     ...
 
@@ -220,10 +221,12 @@ Lets create a second table, `email_addresses`, which references the `users` tabl
     ...     Column('address_id', Integer, primary_key=True),
     ...     Column('email_address', String(100), nullable=False),
     ...     Column('user_id', Integer, ForeignKey('users.user_id'))).create() # doctest:+ELLIPSIS,+NORMALIZE_WHITESPACE
-    CREATE TABLE email_addresses(
-        address_id INTEGER NOT NULL PRIMARY KEY,
+    CREATE TABLE email_addresses (
+        address_id INTEGER NOT NULL,
         email_address VARCHAR(100) NOT NULL,
-        user_id INTEGER REFERENCES users(user_id)
+        user_id INTEGER,
+        PRIMARY KEY (address_id),
+        FOREIGN KEY(user_id) REFERENCES users (user_id)
     )
     ...
 
index 689b3241b17f347d5a8584cd5b83a417c12187d2..ab0226a41d091cfd74be16086276e8ef651cce81 100644 (file)
@@ -151,7 +151,17 @@ class Mapper(object):
         this is the 'external' version of the method which is not reentrant."""
         if self.__is_compiled:
             return self
-            
+        
+        self._compile_all()
+        
+        # if we're not primary, compile us
+        if self.non_primary:
+            self._do_compile()
+            self._initialize_properties()
+                
+        return self
+    
+    def _compile_all(self):
         # compile all primary mappers
         for mapper in mapper_registry.values():
             if not mapper.__is_compiled:
@@ -162,13 +172,6 @@ class Mapper(object):
             if not mapper.__props_init:
                 mapper._initialize_properties()
         
-        # if we're not primary, compile us
-        if self.non_primary:
-            self._do_compile()
-            self._initialize_properties()
-                
-        return self
-    
     def _check_compile(self):
         if self.non_primary:
             self._do_compile()
@@ -496,6 +499,8 @@ class Mapper(object):
         has already been compiled, then the given MapperProperty is compiled immediately."""
         self.properties[key] = prop
         if self.__is_compiled:
+            # if we're compiled, make sure all the other mappers are compiled too
+            self._compile_all()
             self._compile_property(key, prop, init=True)
             
     def _create_prop_from_column(self, column, skipmissing=False):