On Mon, Mar 8, 2010 at 16:25, Karol Tarcak <[email protected]> wrote: > On Mon, Mar 8, 2010 at 15:03, Gaetan de Menten <[email protected]> wrote: >> >> You can fix this in different ways. One option would be to configure >> the session differently: >> session.configure(autoflush=False) >> > > Thanks a lot... The following somehow didn't work out: > > session = scoped_session(sessionmaker(autoflush=False))
you need to either reconfigure the existing session instance using session.configure (as above) or tell Elixir to use your custom session, by using one of: __session__ = session # in the module(s) containing your entities using_options(session=session) # in each entity elixir.session = session # only once but *before* you declare any of your entities (this is simplest but can be tricky). > But anyhow. Is there a particular reason why I should use autoflush? In some case, it can be handy: suppose you have many objects in your session, and you don't flush. If you do a query without autoflush, you'll get the results without all those objects in your session. > How could be the above example be modified to work with autoflush? Character.query.all() matrix = Movie(title='Matrix') rabbit = Character(name='The White Rabbit') matrix.characters.append(rabbit) # long exception .... session.commit() Hope it helps, -- Gaƫtan de Menten -- 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.
