Christopher Arndt wrote:

>> Oops I crossed my words, I though assign_mapper and wrote
>> active_mapper sorry :)
>
> What do people mean when they say "plain SA"? With or without assign
> mapper? Are there really people that like to manage session contexts
> on their own? ;-)
>
> Or does "plain SA" even mean using only the database abstraction
> features of SA?

I have seen Mike Bayer talk a lot about getting rid of or changing the
meaning of assign_mapper at some point down the road, so I have switched
to this instead in my "plain" SQLAlchemy projects:

     from sqlalchemy import MetaData, create_session
     from sqlalchemy.ext.sessioncontext import SessionContext
     from sqlalchemy.orm.mapper import global_extensions

     # create a session context and add the mapper extension globally
     # so I don't have to use assign_mapper anymore
     context = SessionContext(create_session)
     global_extensions.append(context.mapper_extension)


     # a base class for all my model objects that gives me a `query`
     # attribute that I can use to get a Query() object on the class
     class ModelBase(object):
         class __metaclass__(type):
             @property
             def query(cls):
                 return Query(cls)

         def __init__(self, **kwargs):
             for key, value in kwargs.items():
                 setattr(self, key, value)


This way, I get the benefits of the session context mapper extension,
and my base class for my model objects gives me a `query` property which
gives me my convenience methods:

     customer = Customer.query.get(1)
     customers = Customer.query.select()

... etc.

--
Jonathan LaCour
http://cleverdevil.org




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

Reply via email to