Hello Daniel,

> I hate to sound like a broken record, but this is how Hibernate does it. 
> New objects become associated with a session by calling session.save(obj), 
> and objects that already exist in the database become associated with the 
> session by calling session.update(obj). I wouldn't be easy enough to make a 
> custom base class that would associate the object with the "current" 
> session (whatever that may be). Here's a trivial example:
(...)

This look quite nice, and I belive this is also what Michael
has in mind.

> I think it's better to leave this type of magic up to the user rather
> than have it included in the core of SA itself. It should be an
> explicit choice of the developer to use magic; it should not be the
> default behavior of the library.

Agreed.

> >    MyClass(_sa_session=s1)
> >
> >would probably solve it, but that doesn't look like something
> >nice to have spread around the code. It'd probably be possible
> >to use a metaclass to stick the keyword parameter somehow.
> 
> As demonstrated above, a metaclass is not necessary. Although that would 
> certainly be possible.

If you change SA itself, of course the metaclass isn't needed. :-)

The metaclass would be needed if SA wasn't changed, and I had to
introduce the _sa_session as a keyword argument dynamically in
the patched __init__(), as I described above. That's certainly
something I prefer not to do.

> Stuff like this shouldn't involve too much deep hacking into the SA core if 
> it (the core) is kept simple, and doesn't do too much of its own magic.

+1

-- 
Gustavo Niemeyer
http://niemeyer.net


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to