I want to define the relationship for my users and their groups with
declarative style (so that the relating model can inherit Timestamp
mixin and Tablename mixin):
class User(DeclarativeBase, Tablename, TimestampMixin):
'''User avatar is named after its id.
A user may be a student or teacher or both.
'''
id = Column(Integer, Sequence('user_id_seq'), primary_key=True)
username = Column(String(30), index=True, nullable=False, unique=True)
password = Column(String(30), index=True, nullable=False)
class Group(DeclarativeBase, Tablename, TimestampMixin):
id = Column(Integer, Sequence('group_id_seq'), primary_key=True)
name = Column(Unicode(20), unique=True, nullable=False)
display = Column(Unicode(255))
class GroupUser(DeclarativeBase, Tablename, TimestampMixin):
id = Column(Integer, Sequence('group_user_id_seq'), primary_key=True)
user = Column(Integer, ForeignKey('user.id'), index=True),
group = Column(Integer, ForeignKey('group.id'), index=True)
I was wondering how to associate User and Group with GroupUser with
GroupUser as the association object/proxy? The sqlalchemy docs only
mention only mention association tables, or non-declarative manual mapping.
Thanks.
For SQLAlchemy questions, you're better off asking on
sqlal...@googlegroups.com.
On 07/09/2010 10:39, Jerry Fleming wrote:
> class GroupUser(DeclarativeBase, Tablename, TimestampMixin):
> id = Column(Integer, Sequence('group_user_id_seq'), primary_key=True)
> user = Column(Integer, ForeignKey('user.id'), index=True),
> group = Column(Integer, ForeignKey('group.id'), index=True)
>
> I was wondering how to associate User and Group with GroupUser with
> GroupUser as the association object/proxy? The sqlalchemy docs only
> mention only mention association tables, or non-declarative manual mapping.
Yes, declarative doesn't currently work like this.
The functionality could probably be added, but Michael Bayer would be
the man to decide how to do that :-)
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk