From: Mike Bayer Date: Tue, 3 Aug 2010 16:56:02 +0000 (-0400) Subject: - dont like this note X-Git-Tag: rel_0_6_4~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=54feab41f9fc81966da1f6e7bc35344c8ba5f604;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - dont like this note - rewrite this section, also don't talk about extensions anymore since they will be replaced --- diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 90ce5b7798..2310f01ce3 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -369,20 +369,25 @@ such as those which already take advantage of the data-driven nature of Mapper Configuration ==================== -Configuration of mappers is done with the -:func:`~sqlalchemy.orm.mapper` function and all the possible mapper -configuration parameters can be found in the documentation for that -function. - -:func:`~sqlalchemy.orm.mapper` is still used by declaratively mapped -classes and keyword parameters to the function can be passed by -placing them in the ``__mapper_args__`` class variable:: - +Declarative makes use of the :func:`~.orm.mapper` function internally +when it creates the mapping to the declared table. The options +for :func:`~.orm.mapper` are passed directly through via the ``__mapper_args__`` +class attribute. As always, arguments which reference locally +mapped columns can reference them directly from within the +class declaration:: + + from datetime import datetime + class Widget(Base): __tablename__ = 'widgets' + id = Column(Integer, primary_key=True) + timestamp = Column(DateTime, nullable=False) - __mapper_args__ = {'extension': MyWidgetExtension()} + __mapper_args__ = { + 'version_id_col': timestamp, + 'version_id_generator': lambda v:datetime.now() + } Inheritance Configuration ========================= @@ -520,11 +525,6 @@ share some functionality, often a set of columns, across many classes. The normal Python idiom would be to put this common code into a base class and have all the other classes subclass this class. -.. note:: Mixins are an entirely optional feature when using declarative, - and are not required for any configuration. Users who don't need - to define sets of attributes common among many classes can - skip this section. - When using :mod:`~sqlalchemy.ext.declarative`, this need is met by using a "mixin class". A mixin class is one that isn't mapped to a table and doesn't subclass the declarative :class:`Base`. For example::