views:

590

answers:

4

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?

Thanks!

+1  A: 

via the __table__ attribute on your declarative class

A: 

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

users.select()

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

session.query(User)

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

conn.execute(users.update(users.c.name=='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.

Base.metadata.tables["users"]

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

Thanks

+3  A: 

well it works for me:

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

users = Users()
print users.__table__.select()

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

GHZ
Note it is ____table____ NOT ____tablename____
Ben
A: 

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