On Aug 24, 2010, at 7:54 PM, waugust wrote: > Greetings, > > I was playing around and trying to extend the DeclarativeBase with > some "Elixir" like functions... > > I may be to green in Python itself that I'm missing something though, > here's what I got... > > class ModelBase(DeclarativeMeta): > > @classmethod > def get(cls, id): > row = meta.Session.query(cls).filter_by(id=id).one() > return row > > DeclarativeBase = declarative_base(metaclass=ModelBase) > metadata = DeclarativeBase.metadata
A metaclass is a subclass of "type", and represents special behavior added to your classes' type, not the class itself. If that doesn't make much sense, this is common as metaclasses are a little hard to grasp at first, theres a decent intro at http://www.voidspace.org.uk/python/articles/metaclasses.shtml. anyway if you're just looking for classmethods that are common to all your mapped classes, use either a mixin (plenty of mixin info in the declarative docs) or specify a base class to declarative_meta using "cls" - the resulting class will be a subclass of the class you send. It defaults to "object". > > uhhh... so how does the introspection work here (if any)? I'm I a bit > too naive here? calling cls.__class__, cls.__table__, or > cls.__call__() doesn't seem to do it... > > -- > 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.