On Sat, Oct 3, 2009 at 20:30, Eloff <[email protected]> wrote:

> I asked about this on #sqlalchemy a while back, and the answer IIRC is
> that it has to do with something elixir is passing (or not passing)
> during the creation of the tables and mappers. Apparently it's not
> recommended practice in sqlalchemy.
>
> That being as it may be, how can I change this behavior? I usually
> explicitly add objects to the session when I mean to, and I often keep
> local sessions around to prevent unrelated queries from being lumped
> into one transaction. Often that means I need to explicitly remove an
> object from the scoped_session, and add it to the local session after
> creation.
>
> class Foo(Entity):
>     pass
>
> s = LocalSession()
> f = Foo()
> s.add(f) # ERROR object already attached to a session

There are several options...

The most granular one, but also the most tedious, is to use

    using_mapper_options(save_on_init=False)

in each of your entities where you don't want that behavior.

For an example, see:
http://elixir.ematia.de/trac/browser/elixir/tags/0.7.0/tests/test_options.py#L159

If you don't want to specify that on a per-entity basis, you could add
the following line before you declare your entities:

elixir.options_defaults['mapper_options'] = {'save_on_init': False}

or, if you don't want to use the default session at all, you can add:

__session__ = None

at the beginning of the module(s) where your entities are declared.

Hope it helps,
-- 
Gaëtan de Menten
http://openhex.org

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

Reply via email to