On Oct 4, 2011, at 9:37 AM, neurino wrote:

> Hi Michael,
> 
> the reason is Parent does not know its children until another relationship is 
> set (`id_str` in the code above).
> 
> Consider this form validation part:
> 
> if form.validate():
>     user_strat = form.bind(UserStratigraphy())
> 
> I cannot bind prior creating an instance and this is quite a common situation.
> 
> I can always go with manual adds of course but...

manual is never required for something that follows a repeatable rule - it's 
just mapper events are the worst place to do things, and yes, it has always 
been a restriction that the Session cannot be reliably manipulated from inside 
the flush procedure.   You can add event listeners to the relationship in 
question using @validates, which then apply the corresponding extra objects.   
I'd still keep this at the object level.   As a fallback, you'd hit it with the 
before_flush event.    An eventual feature for "before_flush" is to break it 
into sub-events that can be limited to certain classes and statuses, but this 
is very easy to roll manually doing a simple "[obj for obj in session.dirty if 
isinstance(obj, MyClass)]" for now.



-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to