Mike,

Thank you for posting tips like that and keeping them up to date.
There is small typo in load_environment section -- init_model is
referred as "init_engine".

I'm using little different approach. Instead of defining init_model()
and calling scoped_session() with bind parameter I simply assign
engine to bind property of MetaData instance. Creating session bound
to engine directly doesn't seem to be right way to me although it
works in cases when single engine is used and I'm not sure if it is
reliable to span session across multiply engines.  Anyway, the
following is how it looks like:

--- CUT HERE ---

---------- project/model/__init__.py ----------
from pylons import config
from project.model.tables import *
from project.model.objects import *
from sqlalchemy.orm import mapper, scoped_session, sessionmaker

Session = scoped_session(sessionmaker(autoflush=True,
transactional=True))
mapper(Entity, entities, ...)


---------- project/config/environment.py ----------
...
from project import model

def load_environment(global_conf, app_conf):
    ...
    model.meta.bind = engine_from_config(config, 'sqlalchemy.')

---------- project/model/tables.py ----------
from sqlalchemy import MetaData, Table, Column, types, ForeignKey

__all__ = ['meta', 'entities']
meta = MetaData()
entities = Table('entities', meta, ...)


---------- project/model/objects.py ----------
class Entity(object): pass

--- CUT HERE ---

Nice side effect is that MetaData instance methods can be called
without bind parameter once it is bound to engine.

Cheers

On Feb 25, 1:20 am, "Mike Orr" <[EMAIL PROTECTED]> wrote:
> I've put a new SQLAlchemy tutorial in the Pylons official 
> docs.http://wiki.pylonshq.com/display/pylonsdocs/Using+SQLAlchemy+with+Pylons
>
> It's an update of "SQLAlchemy 0.4 for people in a hurry" with the new
> model structure that will be in Pylons 0.9.7 (the init_model()
> function and 'meta' module).  I'll need somebody to test it,
> especially that the variable names & locations are consistent.
>
> Then  we'll need to update the other tutorials to match, especially
> "QuickWiki" and "Making a Pylons Blog".  Christopher Abaid was working
> on QuickWiki, what's its status?  The blog tutorial just needs the
> model module split up. Any volunteers?
>
> There are a few other tutorials and FAQ items that mention SQLAlchemy.
>  These need to be checked for up-to-date-ness, and anything for
> SQLAlchemy 0.3 moved to "SQLAlchemy 0,3 for people in a hurry" or
> deleted.
>
> --
> Mike Orr <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to