Michael Bayer wrote: > the easiest way to have two properties point to the same thing is to > just use a "property" on your class: > > class Foo(object): > def _get_uname(self): > return self.user_name > def _set_uname(self, value): > self.user_name = value > username = property(_get_uname, _set_uname) > > although one of the points of "synonym" was to also allow the name to > be used in select_by() so ill look into restoring it.
That would be good. However, I still have a problem here: Usually, you don't want a simple synonym. For instance, in a legacy database I have tables like the following: CREATE TABLE user ( name character(8) NOT NULL, pwd character(8), CONSTRAINT user_pkey PRIMARY KEY (name) ) Whenever I request the name, it is right padded with blanks which do not matter at all, but lead to all sorts of problems. Moreover, the name is also case insensitive. So I'd like to have a property that transparently gets me a trimmed and lowercased version of the name instead of the real name stored in the database. I want to get 'fred' instead of 'Fred ', 'FRED ' etc. So what I do is the following, as suggested: class User(object): def _get_name(self): return self._name.rstrip(' ').lower() def _set_name(self, value): self._name = value name = property(_get_name, _set_name) mapper(User, user, properties = { '_name': user.c.name, 'name': synonym('_name') } ) The problem is that when I request the user 'fred' with get_by(name='fred'), and it is stored as 'Fred' in the database, it will still not be found, because name is a synonym for _name which is the original column. Any suggestion how to solve this? -- Christoph --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---