On Apr 29, 2007, at 12:11 PM, Martin Aspeli wrote:

>
> When the user saves a form, each form field is saved one-by-one. That
> is, the storage layer is told "save falue foo" and then later "save
> value bar". These calls are isolated, so the storage layer doesn't
> know when the form submit handler is finished saving values.
>

there is a pattern to this, which is that you use a single Session to  
represent the full transaction, i.e. all the form fields being  
modified.  you then wrap the whole submit cycle using this single  
Session, and then you flush() at the end.   thats the entire point of  
the unit of work pattern.  since all the actors within the submit  
cycle share the same session, they all will see the same, consistent  
set of object instances, whether they are persisted or not (although  
a flush() will ensure that the persistent objects thus far will come  
back from query operations too).

an extension to this pattern is to wrap the whole submit cycle within  
SessionTransaction boundaries, so that multiple flush()es all  
participate in the same database transaction which is commited at the  
end.

> Therefore, my idea is to construct a mapper object lazily (on the
> first form field) and attach it to a session immediately (with
> session.save(), I presume).

mappers are intended to be module-level constructs, corresponding to  
table and class design.  unless youre generating classes themselves  
dynamically, i see no reason to construct mappers lazily.

> As the other save-field events come in,
> I'll update the object property-by-property. At the request boundary,
> I can make sure the session is flushed.

yes, just update properties whenever you want, and forget that they  
are even persisted.  the flush() at the end takes care of it for you.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to