Being not the expert at pylons, "yet" I thought someone could maybe
shed some light onto my problem.
Models apparently are recommended to be done in the declarative way.
Ok no one is forcing me to but I generally try to stick to
recommendations unless I really need to stray off the path.
My question is how to do many to many relationships. For example I
have the following two model objects, User and Group. A user can
belong to many groups and a group can have many users.
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
username = Column(Unicode(25), nullable=False, unique=True)
class Group(Base):
__tablename__ = 'groups'
id = Column(Integer, primary_key=True)
name = Column(Unicode(25), nullable=False, unique=True)
I would assume using a join table would be the way forward but does
this still have to be declared in the old fashioned way or can it be
done in a declarative way as well? Does sqlalchemy automatically
create the join table?
E.g. (manual join table)
user_group_table = Table('users_groups', Base.metadata,
Column('user_id', Integer, ForeignKey('users.id',
onupdate="CASCADE", ondelete="CASCADE")),
Column('group_id', Integer, ForeignKey('groups.id',
onupdate="CASCADE", ondelete="CASCADE"))
)
Regards,
Pete
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" 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/pylons-discuss?hl=en.