Gloria W wrote:
> Hi all,
> I am trying to use the session syntax to bind to an existing table,
> but I am apparently missing something. I want my session to be bound
> to this:
> 
> my_table = sqlalchemy.Table('my_table', meta, autoload=True,
> autoload_with=engine)
> 
> and if I use the same engine here:
> 
> session = sqlalchemy.orm.sessionmaker(bind=engine, autoflush=True,
> transactional=True)
> 
> isn't the session bound to the table?
> 
> But when I run this:
> 
> all_records = session.query(my_table).all()
> 
> I get this error:
> 
> Traceback (most recent call last):
>[..zip...[
> AttributeError: 'PGCompiler' object has no attribute 'mapped_table'
> 
> The docs I've seen only show session bindings using Table classes, so
> please point me to a good example or give me the quick hint.

The ORM maps your Python classes to tables rather than working with 
tables directly.  You're missing a step in the middle like:

class MyClass(object):
   def my_stuff(self):
      self.yadayada

sqlalchemy.orm.mapper(MyClass, my_table)

all_records = session.query(MyClass).all()

The ORM tutorial lays out the steps in more detail: 
http://www.sqlalchemy.org/docs/04/ormtutorial.html



--~--~---------~--~----~------------~-------~--~----~
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