On Jan 11, 2013, at 1:22 AM, YKdvd wrote:

> 
> SQLA's event system has the "after_attach" session event.  Hooking into this 
> works for new instances I attach to a session with add(), but does't fire 
> when items are loaded from a query - presumably "attached" means direct 
> userland attachment only, not instances being associated with a session via a 
> query. So it's only half the solution - there doesn't seem to be a 
> session-level  event that fires in the latter case?

there is not, you'd use the instance event

> 
> There is a "load" instance-level event, which seems to solve the other half 
> of this.  The QueryContext passed to the handler contains the session, and I 
> can stamp the instance with the Project reference I've stored in the session. 
>  The only drawback is that I apparently need to separately attach the event 
> listener to each project instance class?  

you can associate the instance event with the mapper() callable or Mapper 
class, and it will take effect for all mapped classes.

Using 0.8 you can also associate the listener with a common base class, such as 
your declarative Base, or even a mixin that's common to some subset of classes.

The approach of listening for configured mappers and then associating the 
instance event at that point works as well too but hopefully that shouldn't be 
necessary here.


-- 
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