]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Comparison of many-to-one relation to NULL is
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 21 Nov 2008 03:49:36 +0000 (03:49 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 21 Nov 2008 03:49:36 +0000 (03:49 +0000)
properly converted to IS NOT NULL based on not_().

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

diff --git a/CHANGES b/CHANGES
index ef177b5ead40fc313b33c3264ea8f45cd97a4deb..8899d280ae4ad617df9bf69a38f479a9c1122c61 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,9 @@ CHANGES
     - Query.add_column() can accept FromClause objects
       in the same manner as session.query() can.
 
+    - Comparison of many-to-one relation to NULL is
+      properly converted to IS NOT NULL based on not_().
+      
 - sql
     - Added NotImplementedError for params() method
       on Insert/Update/Delete constructs.  These items
index 156712bc77dcf5b50280b8e30e49c9fee814888f..58aa71c6aacb59592672f9fe83d1d82a0decca7b 100644 (file)
@@ -392,10 +392,12 @@ class LazyLoader(AbstractRelationLoader):
                 binary.left = binary.right
                 binary.right = expression.null()
                 binary.operator = operators.is_
+                binary.negate = operators.isnot
             elif isinstance(binary.right, expression._BindParamClause) and binary.right.key in bind_to_col:
                 binary.right = expression.null()
                 binary.operator = operators.is_
-        
+                binary.negate = operators.isnot
+
         criterion = visitors.cloned_traverse(criterion, {}, {'binary':visit_binary})
         if adapt_source:
             criterion = adapt_source(criterion)
index 34372b83ab34d35d1f0d943e576ffd00fa479374..6b74b94175e3e36de3c1bbfb1c62d4a213f1516e 100644 (file)
@@ -353,7 +353,17 @@ class OperatorTest(QueryTest, AssertsCompiledSQL):
                 self.assert_(compiled == fwd_sql or compiled == rev_sql,
                              "\n'" + compiled + "'\n does not match\n'" +
                              fwd_sql + "'\n or\n'" + rev_sql + "'")
-
+    
+    def test_negated_null(self):
+        self._test(User.id == None, "users.id IS NULL")
+        self._test(~(User.id==None), "users.id IS NOT NULL")
+        self._test(None == User.id, "users.id IS NULL")
+        self._test(~(None == User.id), "users.id IS NOT NULL")
+        self._test(Address.user == None, "addresses.user_id IS NULL")
+        self._test(~(Address.user==None), "addresses.user_id IS NOT NULL")
+        self._test(None == Address.user, "addresses.user_id IS NULL")
+        self._test(~(None == Address.user), "addresses.user_id IS NOT NULL")
+        
     def test_relation(self):
         self._test(User.addresses.any(Address.id==17), 
                         "EXISTS (SELECT 1 "