Great, Thanks for the pointer Michael. I'll use the code below. Also,
I second removing (or making optional) the 'autosave' feature from
Session.mapper - it is too brittle in it's currently form. I was also
thinking of putting in a per-instance .save() method which will be
equivalent to session.save(self). It's a more compact way of doing
things and close to how things were done in assignmapper.

On Sep 2, 9:08 am, Michael Bayer <[EMAIL PROTECTED]> wrote:
> Well all that we have in that extension right now is the "query"
> attribute.   this attribute is easy enough to construct, based on how
> its done in the scoping.py module:
>
> def query(class_):
>          class q(object):
>              def __getattr__(s, key):
>                  return getattr(Session.query(class_), key)
>              def __call__(s):
>                  return Session.query(class_)
>         return q
>
> MyClass.query = query(MyClass)
>
> clearly I'm going to have to get this recipe to be a little more
> widely available somehow (or maybe remove the "autosave" from
> Session.mapper...)
>
> On Sep 2, 2007, at 1:49 AM, Haseeb wrote:
>
>
>
> > You're right - I am using Session.mapper which I took off the pylons
> > tutorials. I'm mainly using Session.mapper to get the old assignmapper
> > functionality of the 0.3x tree. Is there a way to get assignmapper
> > functionality in 0.4x without losing the ability to control when an
> > object gets added to the session?
>
> > Thanks.
>
> > On Sep 1, 3:53 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> >> you probably dont want to save() the object to the session until its
> >> in a decent state.
>
> >> Note that the usage of Session.mapper, which is going to "autosave"
> >> new objects to the session, is not recommended, since you cant
> >> control when an object gets saved.  I'm pretty sure this has been
> >> taken off the pylons tutorials and such.
>
> >> On Sep 1, 2007, at 5:53 PM, Haseeb wrote:
>
> >>> I'm using 0.4b4's scoped_session + sessionmaker with autoflush=True.
> >>> Is there a way to prevent autoflushing an object when a query is run
> >>> on an unrelated table? I have a partially constructed object and I
> >>> need to execute queries on other tables to populate certain
> >>> fields on
> >>> the object. These queries end up trying to flush my partially
> >>> constructed object which results in 'IntegrityError's because
> >>> certain
> >>> fields are not yet populated. I can change the ordering in which
> >>> fields are populated but is there a better way to manage when an
> >>> object is fully constructed and ready to be autoflushed?
>
> >>> Thanks.


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

Reply via email to