On Mon, 4 Sep 2006 16:21:33 +0200 Enrico Morelli <[EMAIL PROTECTED]> wrote:
> On Mon, 04 Sep 2006 15:51:06 +0200 > Sol <[EMAIL PROTECTED]> wrote: > > > Hello, not sure if i got you right, but here is what i think. > > > > > users_projects=Table('users_projects', metadata, > > > Column('id_users', Integer, ForeignKey('users.id_users')), > > > Column('id_projects', Integer, > > > ForeignKey('projects.id_projects')), ) > > > > > > users_projects.create() > > > > > > class Users(object): > > > pass > > > class Projects(object): > > > pass > > > > > > umapper=mapper(Users, users) > > > > umapper = mapper(Users, users, properties = dict( > > projects = relation(Projects, secondary = users_projects), > > )) > > > > > pmapper=mapper(Projects, projects, properties={ > > > 'users' : relation(Users, secondary=users_projects, > > > backref="projects"), } > > > ) > > > > > > > > > > > > u=session.query(Users).select() > > > > > > for i in range(len(u)): > > > pr=u[i].fk_project.split(',') > > > for p in range(len(pr)-1): > > > > > > pname=session.query(Projects).selectfirst(projects.c.id_projects==pr[p]) > > > ???????? > > > > all_usuers = session.query(Users).select() > > > > for user in all_users: > > project_ids = user.fk_project.split(',') > > for project_id in project_ids: > > project = session.get(Projects, project_id) > > user.projects.append(project) > > > > session.flush() > > > > > > > Actually, the users table has a fk_project field like 1,15,3,. > > > Each > > Now dismiss the fk_project field altogether, you do not need it with > > many-to-many relationships. > > > > Thanks seems to works. But when I try to get some results I obtain > an object. > > >>> u=session.query(Users).selectfirst(users.c.login=='morelli') > > >>> u.login > morelli > > >>> u.projects > [<__main__.Projects object at 0xb77f8cac>] > > How can I obtain the project names related to a given user? > > Thanks > I found that I can obtain using: u.projects[0].project -- ------------------------------------------------------------------- (o_ (o_ //\ Coltivate Linux che tanto Windows si pianta da solo. (/)_ V_/_ +------------------------------------------------------------------+ | ENRICO MORELLI | email: [EMAIL PROTECTED] | | * * * * | phone: +39 055 4574269 | | University of Florence | fax : +39 055 4574253 | | CERM - via Sacconi, 6 - 50019 Sesto Fiorentino (FI) - ITALY | +------------------------------------------------------------------+ ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Sqlalchemy-users mailing list Sqlalchemy-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users