On Tuesday, April 1, 2014 2:46:06 AM UTC-7, Chung WONG wrote:
>
> For example:
>
> *DBSession =
> scoped_session(sessionmaker(extension=ZopeTransactionExtension()))*
> *class User(Base):*
> * id = Column(Integer,Sequence('user_id_seq'), primary_key=True)*
> * username = Column(Unicode(255), unique=True)*
>
>
> *def some_view(request):*
> * user=User(username='me')*
>
> * return user.id <http://user.id>*
>
> the return obviously will be None, because the session is not committed
> yet.
> To accomplish the goal, I have to add *DBSession.flush() *before the
> return to obtain an *id* from the DB.
>
> However, I believe there should be a elegant way for doing this.
>
> Does anyone have any idea about this?
>
As far as I know, using flush() is your only option (which doesn't seem
particularly inelegant to me).
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/d/optout.