On Dec 22, 2007, at 6:38 PM, andresj wrote:
> > Hello, I am using SQLAlchemy 0.4.0.1, and am overriding attribute > behavior as described in > http://www.sqlalchemy.org/docs/04/mappers.html#advdatamapping_mapper_overriding > > , > which mainly says to set another name for the columns (like > '_something' instead of 'something'), use Python's property() method > to do whatever I want, and use `sqlalchemy.orm.synonym()` to make it > available in Query().filter_by() expressions. > > But when I try to use my custom properties in filter() expressions, > such as `Resource.query.filter(Resource.url.endswith('.html'))`, it > won't work. I assume this is because the property doesn't have an > endswith method like `sqlalchemy.orm.attributes.InstrumentedAttribute` > does (i.e. `Resource.query.filter(Resource._url.endswith('.html'))` > does work). > > Is there a way of making it work? I know it's just one character but > it makes it confusing to use th underscore in some attributes and in > some not; plus it looks ugly. So, is there a way of adding the > neccessary methods to my property? Or any other way which will make it > work normally? > a synonym() is used so that your attributes are properly available in filter(). This functionality has been vastly improved in the current SVN trunk which resolves all the issues you outline above, and will be available in release 0.4.2. If you checkout the SVN trunk, you can do: class MyAddress(object): def _set_email(self, email): self._email = email def _get_email(self): return self._email email = property(_get_email, _set_email) mapper(MyAddress, addresses_table, properties = { 'email':synonym('_email', map_column=True) }) which automatically maps the column to the "_email" attribute, and also instruments the "email" property with the SQL comparator methods. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
