le 24.09.2008 19:31 Kirk Strauser a écrit:
> I think I'm about to give up on the idea of TurboGears + SQLAlchemy. I don't
> know why the following isn't flushing changes out to our database even though
> I
> use almost identical code outside TG in other applications all the time.
> Here, 'Types.py' is a module containing nothing but SA table and mapper
> definitions.
>
> @expose(template='lite.templates.backoffice.shipmentdetail')
> def updatedeliveryinfo(self, **args):
> shipinfo = session.query(Types.Ship).filter_by(shipid=args['shipid'])
> shipinfo = shipinfo.join(['BofReg', 'XrsCust'])
> shipinfo =
> shipinfo.filter(Types.XrsCust.xrsgrpcd==identity.current.user.groupcode).one()
> shipinfo.destincd = 'HI CAN HAZ IT'
> session.commit()
> flash('updated %s' % shipinfo.destincd)
> redirect('shipmentdetail/%s' % args['shipid'])
>
> So I'm updating an object's property and committing the session, but it has
> the old value when I load the next page (and verified by querying the table
> directly via psql in a terminal window). Throw a rope to a drowning man?
>
I'm not using plain SQLAlchemy but I defined my models with Elixir (much
simpler as you define both table and mapper at the same time and it's
enough for me :-) ). With Elixir, (and perhaps with plain SA definitions
also), you don't need to bother with the session :
In your case I would write :
@expose(template='lite.templates.backoffice.shipmentdetail')
def updatedeliveryinfo(self, **args):
shipinfo = Types.Ship.query.filter_by(shipid=args['shipid'])
shipinfo = shipinfo.join(['BofReg', 'XrsCust'])
shipinfo =
shipinfo.filter(Types.XrsCust.xrsgrpcd==identity.current.user.groupcode).one()
shipinfo.destincd = 'HI CAN HAZ IT'
flash('updated %s' % shipinfo.destincd)
redirect('shipmentdetail/%s' % args['shipid'])
That's all. You don't need to commit, this is done by TG automatically.
Perhaps you can adapt this to your specific case...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---