Hello,

ok so I got the connection, select statements working using
turbogears, assign_mapper and sqlalchemy.
Now i need to work out the relation.

User has a one to many relation with address, email, accounts.
In reverse: address, email and accounts have many to one...

#here is my table
user_table = sqlalchemy.Table('user', metadata, autoload=True)
uaddress_table = sqlalchemy.Table('uaddress', metadata, autoload=True)
uemail_table = sqlalchemy.Table('uemail', metadata, autoload=True)
uaccounts_table = sqlalchemy.Table('uaccounts', metadata, autoload=True)

#my python class
class User(object):
    pass
class Address(object):
    pass
class Email(object):
    pass
class Accounts(object):
    pass

#mapper for table to class
#1 to many

The Primary key on:
User is 'User_Sid'
on Address is 'User_Sid' and 'Address_Sid'
on Email is 'User_Sid' and 'email_Sid'
on Accounts is 'User_Sid' and 'accounts_Sid'

Is this done correctly?
usermapper=assign_mapper(session.context,User,user_table, properties={
    'address':sqlalchemy.relation(Address),
    'email':sqlalchemy.relation(Email),
    'accounts':sqlalchemy.relation(Accounts),
    })

 Do I have to create a relation on these mappers?

uaddressmapper=assign_mapper(session.context,Address,uaddress_table)
uemailmapper=assign_mapper(session.context,Email,uemail_table)
uaccountsmapper=assign_mapper(session.context,Account,uaccount_table)

What if the relation was many to many? How would the properties={??} look like?



In controller.py how do I use my mapper with relations?
u=model.User()

Do I do:
a=u.address()
or
a=model.address()
u.address=a

How do I save them? Do I save one by one? u.flush() then a.flush() or
u.flash() saves it all???


Thanks,
Lucas

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