]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- options() method on SelectResults now implemented "generatively"
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Mar 2007 01:31:41 +0000 (01:31 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Mar 2007 01:31:41 +0000 (01:31 +0000)
like the rest of the SelectResults methods [ticket:472]

CHANGES
lib/sqlalchemy/ext/selectresults.py
test/ext/selectresults.py

diff --git a/CHANGES b/CHANGES
index e3fc2832f0901b55c13950c2babd93312fba7cf9..f263bcdd195815d4b4227442defb4754d48d8c5d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -41,6 +41,9 @@
       (since its not polymorphic) which breaks in bi-directional relationships
       (i.e. C has its A, but A's backref will lazyload it as a different 
       instance of type "B") [ticket:500]
+- extensions:
+    - options() method on SelectResults now implemented "generatively"
+      like the rest of the SelectResults methods [ticket:472]
 
 0.3.5
 - sql:
index d65a02f01d280a14144468ca8104a5fe933c346d..f498e26b0641e36d546f6f94a876354c49b9b5fe 100644 (file)
@@ -33,12 +33,14 @@ class SelectResults(object):
         self._joinpoint = joinpoint or (self._query.table, self._query.mapper)
 
     def options(self,*args, **kwargs):
-        """Transform the original mapper query form to an alternate form
+        """Apply mapper options to the underlying query.
 
         See also ``Query.options``.
         """
 
-        self._query = self._query.options(*args, **kwargs)
+        new = self.clone()
+        new._query = new._query.options(*args, **kwargs)
+        return new
 
     def count(self):
         """Execute the SQL ``count()`` function against the ``SelectResults`` criterion."""
index ebb0e69e2d49d304bca78311a3913ce78c935923..ca052ad3b250bfd06b3930159321030383731d2c 100644 (file)
@@ -70,6 +70,14 @@ class SelectResultsTest(PersistTest):
         assert self.res.filter(Foo.c.bar < 30).count() == 30
         res2 = self.res.filter(Foo.c.bar < 30).filter(Foo.c.bar > 10)
         assert res2.count() == 19
+    
+    def test_options(self):
+        class ext1(MapperExtension):
+            def populate_instance(self, mapper, selectcontext, row, instance, identitykey, isnew):
+                instance.TEST = "hello world"
+                return EXT_PASS
+        objectstore.clear()
+        assert self.res.options(extension(ext1()))[0].TEST == "hello world"
         
     def test_order_by(self):
         assert self.res.order_by([Foo.c.bar])[0].bar == 0