On Feb 3, 10:29 pm, pkraus <[email protected]> wrote: > I have a model setup to represent a customer. > I have a method on that model that returns a representation of that > customer as a dictionary. > In my controller i convert that dictionary to json and feed it to a page > via json. > > On my page i have it setup so that when a field is updated I update that > field using ajax. > > In the controller i get my customer, set the new value an the field and > then I want to return from the ajax call a new version of the customer as > json. > > The problem is that the changes haven't been committed to the database and > even thought the field has been changed when i call Customer.as_dict
That looks like a @classmethod. Wouldn't customer.as_dict (a normal method with self, not cls) do the right thing? Don't you already have a customer object with the correct values? I realize you'd need to fiddle the names to add a second as_dict method. If you're retrieving a Customer object through the SQLAlchemy session using the primary key, I'd expect SQLAlchemy to return the modified object. You might check that also. (Does this make sense or did I totally misunderstand what you're doing.) and > send it back as json its the old values. > > Not a big deal i have worked around this by doing the update and then doing > a request after the update for the json. However it would be nice and > "cleaner" to just pass the value back dodging the second request. How can I > force the commit? DBSession.flush() doesn't work. transaction.commit() > breaks just about everything. For instance if you are using > request.identity['user'] in a template you will get errors after the > transaction commit. > > How can I force the update? > > I could just change the dictionary value to the new value before sending it > back but the method that handles these updates in the controller is pretty > generic so i would have to add a bunch of code to get the fields set > correctly if i manually updated it before the return. -- 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.

