Commits

Mike Bayer committed e22ac61

- cleanup to the last commit
- 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].

  • Participants
  • Parent commits 602c140

Comments (0)

Files changed (5)

     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

File lib/sqlalchemy/orm/interfaces.py

             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)
     """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()

File lib/sqlalchemy/orm/query.py

     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()
 
 
         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:

File lib/sqlalchemy/orm/strategies.py

         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:

File test/orm/mapper.py

             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):
             {'user_id' : 9, 'addresses' : (Address, [])}
             )
 
-    def testcustom(self):
+    def testcustomeagerquery(self):
         mapper(User, users, properties={
             'addresses':relation(Address, lazy=False)
         })
         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)