From 0171bb8d5d2825f8568215d94cf612a0cb88e048 Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Thu, 5 Jan 2006 12:53:39 +0000
Subject: [PATCH] Added parameter join_table and join_column to
 asSqlExpression. Changed code layout.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@5026 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5Form/Selection.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/product/ERP5Form/Selection.py b/product/ERP5Form/Selection.py
index ad7f9aef1b..c55e7e9706 100755
--- a/product/ERP5Form/Selection.py
+++ b/product/ERP5Form/Selection.py
@@ -378,16 +378,21 @@ class DomainSelection(Acquisition.Implicit, Traversable, Persistent):
     return
 
   security.declarePublic('asSqlExpression')
-  def asSqlExpression(self, table_map=None, domain_id=None, exclude_domain_id=None, strict_membership=0):
+  def asSqlExpression(self, table_map=None, domain_id=None, 
+                      exclude_domain_id=None, strict_membership=0,
+                      join_table="catalog", join_column="uid"):
     join_expression = []
     for k, d in self.domain_dict.items():
       if k == 'parent':
         # Special treatment for parent
-        join_expression.append(d.getParentSqlExpression(table = 'catalog', strict_membership=strict_membership))
+        join_expression.append(d.getParentSqlExpression(table='catalog', 
+                               strict_membership=strict_membership))
       elif k is not None and getattr(aq_base(d), 'isCategory', 0):
         # This is a category, we must join
-        join_expression.append('catalog.uid = %s_category.uid' % k)
-        join_expression.append(d.asSqlExpression(table = '%s_category' % k, strict_membership=strict_membership))
+        join_expression.append('%s.%s = %s_category.uid' % \
+                               (join_table, join_column, k))
+        join_expression.append(d.asSqlExpression(table='%s_category' % k, 
+                               strict_membership=strict_membership))
     result = "( %s )" % ' AND '.join(join_expression)
     #LOG('asSqlExpression', 0, str(result))
     return result
-- 
2.30.9