On Jan 11, 3:44 pm, Isaac Csandl <[EMAIL PROTECTED]> wrote:
> Here's the little update method in my test project's controller:
>
> @validate(schema=PersonForm(), form='edit')
> def update(self, id):
> person = Person.get(id)
> person.__dict__.update(self.form_result)
> person.flush()
> Session.commit()
> redirect_to(url_for(controller='person', action='index',
> id=None))
>
> That should work... right? (the same few lines work for new objects)
> So it has to be one of those really simple, obvious, things where I'll
> be like "duh, how did I miss THAT?"
Are you sure you're doing the person.__dict__.update in paster shell
and elsewhere? I'm surprised this would work, since SQLAlchemy tracks
changes with its properties on your object, while directly updating
the object dictionary looks prone to bypassing the way SQLAlchemy
tracks object changes. Also note that the way Jonathon copied it
avoided the __dict__ update.
I'd highly suggest:
for attrib, val in self.form_result.iteritems():
setattr(person, attrib, val)
Which will definitely use the existing object properties to update the
object, vs jumping to the objects __dict__ and possibly bypassing the
SA properties.
Cheers,
Ben
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---