]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- cleanup to the last commit
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 19 Oct 2006 07:20:52 +0000 (07:20 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 19 Oct 2006 07:20:52 +0000 (07:20 +0000)
- added contains_eager() MapperOption, used in conjunction with
instances() to specify properties that should be eagerly loaded
from the result set, using their plain column names by default, or translated
given an custom row-translation function. [ticket:347].

CHANGES
lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/strategies.py
test/orm/mapper.py

diff --git a/CHANGES b/CHANGES
index 23e3a78d83effa73aed41278617ff101f560c697..95bd4bc65dd0595dfe3685390746513fdd2bc596 100644 (file)
--- a/CHANGES
+++ b/CHANGES
     methods on MapperExtension have a slightly different method signature
     now as a result of the change; hoping that these methods are not 
     in widespread use as of yet.
+    - instances() method moved to Query now, backwards-compatible 
+    version remains on Mapper.  
+    - added contains_eager() MapperOption, used in conjunction with
+    instances() to specify properties that should be eagerly loaded
+    from the result set, using their plain column names by default, or translated
+    given an custom row-translation function.
     - more rearrangements of unit-of-work commit scheme to better allow
     dependencies within circular flushes to work properly...updated
     task traversal/logging implementation
index 872164d32558c8f433d7aa99ce7f0699c6a4d0b5..8e505bac599b16c6bc58b7a09a29dec1a4147cc1 100644 (file)
@@ -72,7 +72,6 @@ class StrategizedProperty(MapperProperty):
             self._all_strategies[cls] = strategy
             return strategy
     def setup(self, querycontext, **kwargs):
-        print "SP SETUP, KEY", self.key, " STRAT IS ",  self._get_context_strategy(querycontext)
         self._get_context_strategy(querycontext).setup_query(querycontext, **kwargs)
     def execute(self, selectcontext, instance, row, identitykey, isnew):
         self._get_context_strategy(selectcontext).process_row(selectcontext, instance, row, identitykey, isnew)
@@ -132,7 +131,8 @@ class StrategizedOption(PropertyOption):
     """a MapperOption that affects which LoaderStrategy will be used for an operation
     by a StrategizedProperty."""
     def process_query_property(self, context, property):
-        print  "HI " + self.key + " " + property.key
+        context.attributes[(LoaderStrategy, property)] = self.get_strategy_class()
+    def process_selection_property(self, context, property):
         context.attributes[(LoaderStrategy, property)] = self.get_strategy_class()
     def get_strategy_class(self):
         raise NotImplementedError()
index a7021d4722506ad21ec84ba3a7ff26f9b64b217d..222eca5ac7641b782cc8fd93c09d2cc1e3e5d43e 100644 (file)
@@ -273,7 +273,7 @@ class Query(object):
     def execute(self, clauseelement, params=None, *args, **kwargs):
         result = self.session.execute(self.mapper, clauseelement, params=params)
         try:
-            return self.mapper.instances(result, self.session, with_options=self.with_options, **kwargs)
+            return self.instances(result, **kwargs)
         finally:
             result.close()
 
@@ -283,7 +283,7 @@ class Query(object):
 
         session = self.session
         
-        context = SelectionContext(self.mapper, session, **kwargs)
+        context = SelectionContext(self.mapper, session, with_options=self.with_options, **kwargs)
 
         result = util.UniqueAppender([])
         if mappers:
index 88d7f6c52e8056c027b9980d8232da684c041649..84512c5a93a893211cfa4335ed5e3254ccde1592 100644 (file)
@@ -460,20 +460,18 @@ class EagerLoader(AbstractRelationLoader):
         try:
             # decorate the row according to the stored AliasedClauses for this eager load,
             # or look for a user-defined decorator in the SelectContext (which was set up by the contains_eager() option)
-            if selectcontext.attributes.has_key((EagerLoader, self)):
+            if selectcontext.attributes.has_key((EagerLoader, self.parent_property)):
                 # custom row decoration function, placed in the selectcontext by the 
                 # contains_eager() mapper option
-                decorator = selectcontext.attributes[(EagerLoader, self)]
+                decorator = selectcontext.attributes[(EagerLoader, self.parent_property)]
                 if decorator is None:
                     decorated_row = row
                 else:
                     decorated_row = decorator(row)
-                print "OK! ROW IS", decorated_row
             else:
                 # AliasedClauses, keyed to the lead mapper used in the query
                 clauses = self.clauses_by_lead_mapper[selectcontext.mapper]
                 decorated_row = clauses._decorate_row(row)
-                print "OK! DECORATED ROW IS", decorated_row
             # check for identity key
             identity_key = self.mapper.identity_key_from_row(decorated_row)
         except KeyError:
index a048adbd8788d3b165b945f1ddc9ee21c4da8e87..4a401fde835e2b4fe3f32dc7c3cada83e49bc82e 100644 (file)
@@ -477,8 +477,9 @@ class MapperTest(MapperSuperTest):
             print u[0].orders[1].items[0].keywords[1]
         self.assert_sql_count(db, go, 3)
         sess.clear()
-        print "MARK"
+        print "-------MARK----------"
         u = q2.select()
+        print "-------MARK2----------"
         self.assert_sql_count(db, go, 2)
         
 class InheritanceTest(MapperSuperTest):
@@ -874,7 +875,7 @@ class EagerTest(MapperSuperTest):
             {'user_id' : 9, 'addresses' : (Address, [])}
             )
 
-    def testcustom(self):
+    def testcustomeagerquery(self):
         mapper(User, users, properties={
             'addresses':relation(Address, lazy=False)
         })
@@ -883,9 +884,10 @@ class EagerTest(MapperSuperTest):
         selectquery = users.outerjoin(addresses).select(use_labels=True)
         q = create_session().query(User)
         
-        l = q.options(contains_eager('addresses')).instances(selectquery.execute())
-#        l = q.instances(selectquery.execute())
-        self.assert_result(l, User, *user_address_result)
+        def go():
+            l = q.options(contains_eager('addresses')).instances(selectquery.execute())
+            self.assert_result(l, User, *user_address_result)
+        self.assert_sql_count(testbase.db, go, 1)
         
     def testorderby_desc(self):
         m = mapper(Address, addresses)