Hi All,

I have created comparable property "JoinedValues" that represents any
joined columns, e.g. full name for first_name and last_name.
Everything works, fine, except the moment when I try to select this
property explicitly, e.g. like:

session.query(User.full_name)... i get error " 'ClauseList' object has
no attribute 'label'"

Is there a way to make this work?

Thanks in advance,
Alex

P.S. You can find the class below:


class JoinedValuesProperty(object):
    """creates joined values property in the mapped class
        see unit tests for use cases
    """
    def __init__(self,columns,delimiter):
        self.columns = columns
        self.delimiter = delimiter

    def __get__(self, obj, objtype):
        if obj is None:
            return self
        return self.delimiter.join([u"%s"%(getattr(obj,column.key),)
if not getattr(obj,column.key) is None else u'' for column in
self.columns])

    def __set__(self, obj, val):
        for column,value in
zip(self.columns,val.split(self.delimiter)):
            setattr(obj,column.key,value)

    class Comparator(PropComparator):
        supported_methods = {
            'eq': '__eq__',
            'ne': '__ne__',
            'asc_op': 'asc',
            'desc_op': 'desc',
            'like_op': 'like'
        }

        def __clause_element__(self):
            return
sql.expression.ClauseList(*self.prop.descriptor.columns)

        def __eq__(self,other):
            if other is None:
                return sql.and_(*[column == None for column in
self.prop.descriptor.columns])
            else:
                return sql.and_(*[column == val for column,val in
zip(self.prop.descriptor.columns,other.split(self.prop.descriptor.delimiter))])

        def __ne__(self,other):
            if other is None:
                return sql.and_(*[column != None for column in
self.prop.descriptor.columns])
            else:
                return sql.and_(*[column != val for column,val in
zip(self.prop.descriptor.columns,other.split(self.prop.descriptor.delimiter))])

        def desc(self):
            return sql.expression.ClauseList(*[column.desc() for
column in self.prop.descriptor.columns])

        def asc(self):
            return sql.expression.ClauseList(*[column.asc() for column
in self.prop.descriptor.columns])

        def like(self, other, escape=None):
            values = other.split(self.prop.descriptor.delimiter)
            if len(values) == 1:
                return sql.or_(*[column.like(values[0])
                                 for column in
self.prop.descriptor.columns])
            return sql.and_(*[column.like(val)
                              for column,val in
zip(self.prop.descriptor.columns,values)])

        def operate(self, op, *other, **kwargs):
            if op.__name__ in
JoinedValuesProperty.Comparator.supported_methods:
                return
getattr(self,JoinedValuesProperty.Comparator.supported_methods[op.__name__])
(*other)
            raise Exception("method %s not supported"%(op.__name__,))

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to