ok...correct me if I'm wrong.

#we start by importing
from turbogears.database import metadata, session,bind_meta_data
from sqlalchemy.ext.assignmapper import assign_mapper
from turbogears import widgets, validators
import sqlalchemy

#Then we bound to database
> > bind_meta_data()
#create a table object
> > users_table = sqlalchemy.Table('users', metadata, autoload=True)

or you can use:
>tables = []
> for name in engine.execute("SHOW TABLES"):
>     tables[name] = sa.Table(name, metadata, autoload=True)
>
Got another error here. but I guess its fixed in a newer version of
sqlalchemy via ticket 482
File "/usr/lib/python2.4/site-packages/sqlalchemy/databases/mysql.py",
line 320, in reflecttable
    raise exceptions.NoSuchTableError(table.name)
sqlalchemy.exceptions.NoSuchTableError: ('users',)

Next...
> >
> > class Users(object):
> >     pass
> >
> > usersmapper=assign_mapper(Users,users_table)

No need to create a session because:
> assign_mapper on TurboGears Is using SessionContext.
> Yes, if you used assign_mapper instead, your model's classes will be
> implicitly bound to the session context.

> put assign_mapper() in place of mapper()
Are these two the same?
 assign_mapper in TG, is the same as mapper in SA?


> > 2. How do I select a user where User_Sid=100?
> What is the schema of the table?
User_Sid - Primary key, int
first_name
last_name


>
> If User_Sid is the primary key:
>
> User.get(100)
>
> If it's not:
>
> User.select_by(User_Sid=100)
or
> User.select_by(User_sid=100, last_name='Smith')

Ok, now I have the object for my User.get(100) query.
<quote.model.User object at 0x40f039ec>

I can display it by
myuser=User.get(100)
myuser.USERS_SID
myuser.LAST
myuser.FIRST

How can I iterate through myuser fields?

This doesn't work:
for field in User.get(100):
    print field

TypeError: iteration over non-sequence


Thanks for the help.
Lucas
http://www.lucasmanual.com/mywiki/TurboGears

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

Reply via email to