On Aug 9, 2010, at 5:12 PM, flzz wrote:

> Greetings,  I have an object model which I'm persisting with
> SQLAlchemy (0.6.3).  I have a need for one of the objects in the model
> to always merge itself into the session when a new instance is added.
> For example, given
> 
>    sub = Subscription(email=EmailAddress(value='f...@bar.com))
> 
> which will then be added to the model via a dynaimc_loader backed by
> an AppenderQuery
> 
>    model.lists[0].subscriptions.append(sub)
> 
> Given the EmailAddress model enforces uniqueness of the value, I want
> the EmailAddress instance to merge itself into the session without me
> having to manually query for it.

If I'm understanding correctly, that's not as much about merging as it is for 
the "unique object" recipe, which is this:  
http://www.sqlalchemy.org/trac/wiki/UsageRecipes/UniqueObject

which assumes the usage of a scoped_session.   Since you're looking for the 
callable EmailAddress to know about a session and you don't want to pass it in, 
there's not really any other option.



> 
> So far I've explored a SessionExtension and manually passing the
> session into the constructor using a trick I found while searching
> around on this group:
> 
>    sub = Subscription(email=EmailAddress(session=session,
> value='f...@bar.com))



> 
> This does exactly what I want it to but is less than desirable from a
> usability perspective.  I've had no luck with a SessionExtension.  Any
> recommendations?
> 
> Thanks!
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to sqlalch...@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.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@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