[Sqlalchemy-tickets] Issue #3401: get eager_defaults to use RETURNING for ad-hoc SQL, not just colu
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-04-29 04:19:35
|
New issue 3401: get eager_defaults to use RETURNING for ad-hoc SQL, not just column defaults https://bitbucket.org/zzzeek/sqlalchemy/issue/3401/get-eager_defaults-to-use-returning-for-ad Mike Bayer: this might take some rearrangement of persistence logic to work out, but this should work: ``` #!python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class A(Base): __tablename__ = 'a' id = Column(Integer, primary_key=True) value = Column(Integer) #, server_default=FetchedValue()) __mapper_args__ = {'eager_defaults': True} e = create_engine("postgresql://scott:tiger@localhost/test", echo=True) Base.metadata.create_all(e) s = Session(e) a1 = A(value=literal_column("1 + 1")) s.add(a1) s.flush() # does a fetch, unless the server_default above is set. print a1.value ``` also eager_defaults should have a section in the mapper docs describing it beyond just the docstring, now that returning makes it useful. |