~cr3/storm/reference_is_in

« back to all changes in this revision

Viewing changes to storm/references.py

  • Committer: Marc Tardif
  • Date: 2009-06-01 20:58:33 UTC
  • Revision ID: marc.tardif@canonical.com-20090601205833-0v9jpdbiadjepzib
Fixed is_in method in references to support compound key references and added test when passed an empty list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from storm.store import Store, get_where_for_args
23
23
from storm.variables import LazyValue
24
24
from storm.expr import (
25
 
    Select, Column, Exists, ComparableExpr, Expr, In, LeftJoin, Not, SQLRaw,
 
25
    Select, Column, Exists, ComparableExpr, LeftJoin, Or, Not, SQLRaw,
26
26
    compare_columns, compile)
27
27
from storm.info import get_cls_info, get_obj_info
28
28
 
204
204
        return Not(self == other)
205
205
 
206
206
    def is_in(self, others):
207
 
        if not isinstance(others, Expr):
208
 
            others = list(others)
209
 
            for i, other in enumerate(others):
210
 
                where = self._relation.get_where_for_local(other)
211
 
                others[i] = where.expr2
 
207
        others = list(others)
 
208
        if not others:
 
209
            return False
212
210
 
213
 
        return In(self._relation.local_key, others)
 
211
        return Or(*[self._relation.get_where_for_local(other)
 
212
            for other in others])
214
213
 
215
214
 
216
215
class ReferenceSet(object):