all the docs for sql alchemy give INSERT and UPDATE examples using the local table instance (i.e. tablename.update()... )

doing this seems difficult with the declarative syntax, I need to reference Base.metadata.tables["tablename"] for get the table reference.

Am I sposed to do this another way? Is there a different syntax for INSERT and UPDATE recommended when using the declarative syntax? should I just switch to the old way?


+1  A: 

via the __table__ attribute on your declarative class


ok, that'll give me the name of the table as a string but thats really not what I was looking for.

As an example say I anted to make a basic select statement, you could use the following to access the users table

You could alternately use the following to make the query to access the users table via the User class (Declarative syntax)


Now lets say that I want to Update some property, the docs give the following example

conn.execute(users.update('jack'), name='ed')

What is the equivalent syntax for making an update via the User object?

The closest thing I've found is to reach into the table via the Base, the following will give me a reference to the table I'm looking for.


Is this the normal way of doing this, whats the best method?


+3  A: 

well it works for me:

class Users(Base):
    __tablename__   = 'users'
    __table_args__  = {'autoload':True}

users = Users()

...SELECT users.......

Note it is ____table____ NOT ____tablename____

There may be some confusion between table (the object) and tablename (the name of the table, a string). Using the table class attribute works fine for me.

Paul Harrington