Hello,
I have defined following many to many relation:
email_table = Table('email',md,
Column('id',Integer,primary_key=True),
Column('Email',String))
project_table = Table('project',md,
Column('id',Integer,primary_key=True),
Column('Project',String))
hwrep_table = Table('hwrep',md,
Column('id',Integer,primary_key=True),
Column('HWRep',String),
Column('Email_id',Integer,ForeignKey('email.id')))
# project <-> hwrep many-to-many association table
project_hwreps_assoc_table = Table('project_hwreps', md,
Column('Project_id',Integer,ForeignKey('project.id')),
Column('HWRep_id',Integer,ForeignKey('hwrep.id')))
mapper(Email,email_table)
mapper(Project, project_table, properties={'HWReps':relation(HWRep,
secondary=project_hwreps_assoc_table, backref='project')})
mapper(HWRep, hwrep_table, properties={'Projects':relation(Project,
secondary=project_hwreps_assoc_table, backref='hwrep'),
'Email':relation(Email, order_by=Email.id, backref='hwrep')})
Now, this works in SQLA, adding objects, simple queries et al.
However, I have a problem doing a query at SQLA level that will select
email, hwrep name and project name. The simple SQL query is straightforward:
select email.Email, project.Project, hwrep.HWRep from email, project,
hwrep, project_hwreps where hwrep.id = project_hwreps.HWRep_id and
project.id = project_hwreps.Project_id and hwrep.Email_id = Email.id;
I have tested that this query selects just what I want.
However, I would like to be able to use SQLA query mech for this, but I
have trouble constructing the query.
Please advise.
Regards,
Marcin Krol
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---