I am trying to define relations between persons and teams, however there
are multiple possible relationships (player, reserve, coach, trainer).
My current set up defines both Person and Team using declarative base
classes. For completeness sake; the database is already defined by the
front end, thus SQLAlchemy is building on an existing database. In the
snippet below only useful columns are indicated.

class Team(Base):
    __tablename__ = 'scheduler_team'

    id = Column(Integer, primary_key=True)
    name = Column(String(length=50))


class Person(Base):
    __tablename__ = 'scheduler_person'

    id = Column(Integer, primary_key=True)
    name = Column(String(length=50))


team_person = Table('scheduler_team_person', Base.metadata,
    Column('team_id', Integer, ForeignKey('scheduler_team.id')),
    Column('person_id', Integer, ForeignKey('scheduler_person.id')),
    Column('role', String(length=1)),
)

The association table contains an 'extra' field, role, in which the role
value is P, R, C, T (see roles indicated above).

What I am currently trying to the is adding a relation(ship) to the
Person class, like this:

teams = relationship(
    "Team",
    collection_class=set,
    secondary=team_person,
)

However I would like to add another constraint; the relation above will
return all teams, no matter what the 'role' value is. I would like to
limit the role value (in my case to all but trainer), but have not been
successful to do so. Just to be clear; I would like the teams attribute
to contain all the team in which the person is either a player, reserve
or coach, but not trainer. I was hoping to alter the defined
relationship potentially using the explicit listing of primary and/or
second join, but have not been successful (the documentation also hints
to possible solutions using column_property).

Would anyone be able to help out or hint me in the right direction?

Thijs

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

Reply via email to