On 18 February 2011 11:34, Abdul Gaffar <gaffar.infoval...@gmail.com> wrote:
> If anybody can give the complete example of User, Group, permission, > Project table with the association table, that should work with repoze > authentication and authorization framework. > > User table sholud contain > --------------- > user_id, > user_name, > email_address > > Group table should contain > -------------------------- > group_id > group_name > > Permission > ---------- > permission_id > permission_name > > Project_table > ------------- > project_id > project_name > > and the association table should contain > ---------------------------------------- > user_id > group_id > project_id > -------------------------------------------------------- Hi I would do it like this (SA07): engine = create_engine('sqlite://') meta = MetaData(bind=engine) Session = sessionmaker(bind=engine) Base = declarative_base(metadata=meta) def project_creator(tup): return GroupProject(project=tup[0], group=tup[1]) class User(Base): __tablename__ = 'users' id = Column(Integer, primary_key=True) projects = association_proxy('group_projects', 'project', creator=project_creator) class Group(Base): __tablename__ = 'groups' id = Column(Integer, primary_key=True) class Project(Base): __tablename__ = 'projects' id = Column(Integer, primary_key=True) class GroupProject(Base): __tablename__ = 'group_projects' _group_id = Column(Integer, ForeignKey('groups.id'), primary_key=True) _project_id = Column(Integer, ForeignKey('projects.id'), primary_key=True) _user_id = Column(Integer, ForeignKey('users.id'), primary_key=True) group = relationship('Group', uselist=False, backref='group_projects') project = relationship('Project', uselist=False, backref='group_projects') user = relationship('User', uselist=False, backref='group_projects') meta.drop_all() meta.create_all() s = Session() p = Project() g = Group() u = User() s.add_all([u,g,p]) u.projects.append((p, g)) s.flush() assert u.projects[0] == p gp = s.query(GroupProject).one() assert gp.user == u assert gp.group == g assert gp.project == p btw. your permission table has no meaning in your example. Greez, Florian -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.