diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-07-19 19:23:37 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2008-07-19 19:23:37 +0000 |
commit | d56862cbca1796edafab8845fd1852f6183512f8 (patch) | |
tree | 61217e5cefc4e0dc1b25ef8554d6361a80bd5dac /test/ext/declarative.py | |
parent | c5141f2981a69c18338ccabc97067d1d563d43a9 (diff) | |
download | sqlalchemy-d56862cbca1796edafab8845fd1852f6183512f8.tar.gz |
- Some improvements to the _CompileOnAttr mechanism which
should reduce the probability of "Attribute x was
not replaced during compile" warnings. (this generally
applies to SQLA hackers, like Elixir devs).
Diffstat (limited to 'test/ext/declarative.py')
-rw-r--r-- | test/ext/declarative.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/test/ext/declarative.py b/test/ext/declarative.py index 0fafc5999..c7bde6802 100644 --- a/test/ext/declarative.py +++ b/test/ext/declarative.py @@ -3,7 +3,7 @@ import testenv; testenv.configure_for_tests() from sqlalchemy.ext import declarative as decl from testlib import sa, testing from testlib.sa import MetaData, Table, Column, Integer, String, ForeignKey, ForeignKeyConstraint -from testlib.sa.orm import relation, create_session +from testlib.sa.orm import relation, create_session, class_mapper from testlib.testing import eq_ from orm._base import ComparableEntity @@ -113,17 +113,26 @@ class DeclarativeTest(testing.TestBase, testing.AssertsExecutionResults): __tablename__ = 'addresses' id = Column(Integer, primary_key=True) email = Column(String(50)) - user_id = Column(Integer) # note no foreign key + user_id = Column(Integer, ForeignKey('users.id')) class User(Base, ComparableEntity): __tablename__ = 'users' id = Column(Integer, primary_key=True) name = Column(String(50)) addresses = relation("Address", order_by=Address.email, - foreign_keys=Address.user_id, remote_side=Address.user_id, - primaryjoin=id==Address.user_id, + foreign_keys=Address.user_id, + remote_side=Address.user_id, ) - + + # get the mapper for User. User mapper will compile, + # "addresses" relation will call upon Address.user_id for + # its clause element. Address.user_id is a _CompileOnAttr, + # which then calls class_mapper(Address). But ! We're already + # "in compilation", but class_mapper(Address) needs to initialize + # regardless, or COA's assertion fails + # and things generally go downhill from there. + class_mapper(User) + Base.metadata.create_all() sess = create_session() |