From bbc5e7c285a160f148eafa0ab442675fe88551ce Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 28 Jan 2007 23:33:53 +0000 Subject: merged the polymorphic relationship refactoring branch in. i want to go further on that branch and introduce the foreign_keys argument, and further centralize the "intelligence" about the joins and selectables into PropertyLoader so that lazyloader/sync can be simplified, but the current branch goes pretty far. - relations keep track of "polymorphic_primaryjoin", "polymorphic_secondaryjoin" which it derives from the plain primaryjoin/secondaryjoin. - lazy/eagerloaders work from those polymorphic join objects. - the join exported by PropertyLoader to Query/SelectResults is the polymorphic join, so that join_to/etc work properly. - Query builds itself against the base Mapper again, not the "polymorphic" mapper. uses the "polymorphic" version only as appropriate. this helps join_by/join_to/etc to work with polymorphic mappers. - Query will also adapt incoming WHERE criterion to the polymorphic mapper, i.e. the "people" table becomes the "person_join" automatically. - quoting has been modified since labels made out of non-case-sensitive columns could themselves require quoting..so case_sensitive defaults to True if not otherwise specified (used to be based on the identifier itself). - the test harness gets an ORMTest base class and a bunch of the ORM unit tests are using it now, decreases a lot of redundancy. --- lib/sqlalchemy/sql_util.py | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'lib/sqlalchemy/sql_util.py') diff --git a/lib/sqlalchemy/sql_util.py b/lib/sqlalchemy/sql_util.py index 6b87a2dec..10d4495d9 100644 --- a/lib/sqlalchemy/sql_util.py +++ b/lib/sqlalchemy/sql_util.py @@ -135,17 +135,31 @@ class ClauseAdapter(sql.ClauseVisitor): s.c.col1 == table2.c.col1 """ - def __init__(self, selectable): + def __init__(self, selectable, include=None, exclude=None, equivalents=None): self.selectable = selectable + self.include = include + self.exclude = exclude + self.equivalents = equivalents + def include_col(self, col): + if not isinstance(col, sql.ColumnElement): + return None + if self.include is not None: + if col not in self.include: + return None + if self.exclude is not None: + if col in self.exclude: + return None + newcol = self.selectable.corresponding_column(col, raiseerr=False, keys_ok=False) + if newcol is None and self.equivalents is not None and col in self.equivalents: + newcol = self.selectable.corresponding_column(self.equivalents[col], raiseerr=False, keys_ok=False) + return newcol def visit_binary(self, binary): - if isinstance(binary.left, sql.ColumnElement): - col = self.selectable.corresponding_column(binary.left, raiseerr=False, keys_ok=True) - if col is not None: - binary.left = col - if isinstance(binary.right, sql.ColumnElement): - col = self.selectable.corresponding_column(binary.right, raiseerr=False, keys_ok=True) - if col is not None: - binary.right = col + col = self.include_col(binary.left) + if col is not None: + binary.left = col + col = self.include_col(binary.right) + if col is not None: + binary.right = col class ColumnsInClause(sql.ClauseVisitor): """given a selectable, visits clauses and determines if any columns from the clause are in the selectable""" -- cgit v1.2.1