remarkably (actually not so much), 0.4.5 introduces a bug that breaks
particular relation. But using 0.4.4, set up the mapping as such:
orm.mapper(Employee, table_employees, properties={
"what_can_be":orm.relation(Speciality,
primaryjoin=sa.or_(
table_employees.c.first_speciality_id==table_specialities.c.id,
table_employees.c.second_speciality_id==table_specialities.c.id
), uselist=True)
})
orm.mapper(Speciality, table_specialities)
and it will work.
*however*.
this relation cannot be writable in the above form (since there is not
enough information to know which Speciality attaches to which foreign
key column), so I'd suggest you place viewonly=True on the relation.
To be able to write data to the DB based on these relationships, you'd
have to specify separate relations for "first_speciality_id" and
"second_speciality_id" and populate separately.
It also may be easier for the what_can_be relation to be an in-python
join of the two:
class Employee(object):
def what_can_be(self):
return [self.first_speciality, self.second_speciality]
what_can_be = property(what_can_be)
the 0.4.5 issue will be fixed soon.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---