On Sep 1, 2010, at 9:06 AM, girish wrote: > Hi , > In sqlalchemy i am facing issue in getting the column names of the > tbl in lower case when i use auto_load = true.To get the column > names in the lower case, we made a temporary fix shown below. > > class LogRepo(Repository): > > def get_schema(self, table_name): > tbl = Table(table_name, > metadata, > autoload=True, > autoload_with=self.session.bind) > > class LogTable(Entity): > pass > mapper(LogTable, tbl) > columns = {} > for column in LogTable.__dict__: > if not column.startswith('_'): > columns[column.lower()] = LogTable.__dict__[column] > for col in columns: > setattr(LogTable, col, columns[col]) > return LogTable > > Is there any other short way to fix the issue? Please guide me on > this.
That's amazing that the above approach would work. There's plenty of places in the ORM where it assumes the name of a mapped attribute matches the attribute name on the column. Here you'd want to wrap mapper() inside a function that does what you see here: http://www.sqlalchemy.org/docs/mappers.html#attribute-names-for-mapped-columns that is, def mapper(cls, table, **kw): properties = kw.setdefault('properties', {}) properties.update( [(col.name.lower(), col) for col in table.c ) return orm.mapper(cls, table, **kw) > > -- > You received this message because you are subscribed to the Google Groups > "sqlalchemy" group. > To post to this group, send email to sqlalch...@googlegroups.com. > To unsubscribe from this group, send email to > sqlalchemy+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.