I got my web app migrated to pylons 0.9.6.1 and sqlalchemy 0.4.4 with
the exception of a few calls.

As I included the code example in my first post, for some reason the
object does not want to obtain the id it was given when saved.

            heading = Heading('Text')
            heading.page = page_object
            heading.user_id = '1'
            meta.Session.save(heading)
            meta.Session.commit()         # tried with and w/o this
line

            heading_id = heading.heading_id  # get new id...  *****
why does this return None?

the var heading_id still seems to have the value None.  I assume this
has something to do with the autosave property.  I have that and
transactional set to True.

I need to save this heading object then use the id to create or update
another object, but the heading should be created regardless of
whether the 'other object' is successful (e.g. no need to rollback..
besides i can't with a myisam db)  =)


thanks again for your support.. it's very appreciated!

john


On Mar 31, 2:48 pm, Michael Bayer <[EMAIL PROTECTED]> wrote:
> On Mar 31, 2008, at 4:49 PM, johnnyice wrote:
>
>
>
> > What do you recommend instead of scopedsession?
>
> definitely use ScopedSession to manage your Sessions on a thread-local
> basis.    Im talking about a specific "feature" of SS called
> "ScopedSession.mapper", described here:  
> http://www.sqlalchemy.org/docs/04/session.html#unitofwork_contextual_...
>   , which "autosaves" all objects created to that session.   Its this
> particular feature I've never liked but we're sort of stuck with it
> for various reasons.
>
> Usually, people use ScopedSession.mapper to get a variable "query" on
> their classes which produces a Query object.   A more explicit way to
> set this up is to say:
>
> MyClass.query = some_scoped_session.query_property()
>
> Usually I advise people to create a base class for their application
> which carries whatever attributes they'd like their application's
> model classes to have, such as this one which sets up "query" as well
> as a default constructor:
>
> Session = scoped_session(sessionmaker(autoflush=True,
> transactional=True))
>
> class Base(object):
>         query = Session.query
>
>         def __init__(self, **kwargs):
>                 for key in kwargs:
>                         setattr(self, key, kwargs[key])
>
> then your model classes just look like:
>
> class MyClass(Base):
>         # ...
>
> The above approach is particuarly convenient in conjunction with the
> declarative layer too, since in that case you're using a common base
> class anyway.
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to