From: Mike Bayer Date: Tue, 15 Aug 2006 02:02:47 +0000 (+0000) Subject: - eesh ! the tutorial doctest was broken for quite some time. X-Git-Tag: rel_0_2_8~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b313b356e5ba46c892b37fb1105c2de26e4beb2;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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 !) --- diff --git a/CHANGES b/CHANGES index 77c8f7b488..b8320e7b24 100644 --- 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 diff --git a/doc/build/content/tutorial.txt b/doc/build/content/tutorial.txt index cd443653ec..201234e47f 100644 --- a/doc/build/content/tutorial.txt +++ b/doc/build/content/tutorial.txt @@ -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) ) ... diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 689b3241b1..ab0226a41d 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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):