Hey everyone, I am running into a problem with association_proxy attributes in SQLAlchemy 0.5 and python 2.6. I pasted my model (a simplified version) all the way below. My model has a Permission object, Project object and a Group object, and it uses an AccessRule object to grant a permission to a group on a specific project. To test everything I populated my database with one permission instance, one project instance and two group instances. I added the permission object for both groups to the project object. Up to the last line of the interactive shell which illustrates the problem, everything works fine. But when I call project.groups [permission] I don't get a collection of groups which have the specific permission on the project, I just get one group (the last one that was granted the permission). Does anyone have a clue how I can get all the groups from a project which have a certain permission? Cheers,
Dolf. =================== python shell ================================== >>> a=session.query(model.AccessRule) >>> print (a[0].group_id,a[0].project_id,a[0].permission_id) (1L, 1L, 1L) >>> print (a[1].group_id,a[1].project_id,a[1].permission_id) (2L, 1L, 1L) >>> manage=session.query(model.Permission).get(1) >>> manage.permission_name u'manage' >>> manage.permission_id 1L >>> g1=s.query(model.Group).get(1) >>> g1.group_id 1L >>> g2=s.query(model.Group).get(2) >>> g2.group_id 2L >>> pr.permissions[g1] <Permission: name=manage> >>> pr.permissions[g2] <Permission: name=manage> >>> pr.groups[manage] <Group: name=users> =================================== model.py ====================================== def _create_access_rule(group,project,permission): return AccessRule(group,project,permission) class AccessRule(DeclarativeBase): __tablename__ = 'tg_access_rule' def __init__(self,group,project,permission): self.group=group self.project=project self.permission=permission group_id=Column(Integer,ForeignKey ("tg_group.group_id"),primary_key=True) project_id=Column(Integer,ForeignKey ("project.project_id"),primary_key=True) permission_id=Column(Integer,ForeignKey ("tg_permission.permission_id"),primary_key=True) class Group(DeclarativeBase): __tablename__ = 'tg_group' group_id = Column(Integer, autoincrement=True, primary_key=True) group_name = Column(Unicode(16), unique=True, nullable=False) permissions_by_project = relation (AccessRule,collection_class=attribute_mapped_collection ('project'),backref='group') permissions=association_proxy ('permissions_by_project','permission',creator=_create_access_rule) class Permission(DeclarativeBase): __tablename__ = 'tg_permission' permission_id = Column(Integer, autoincrement=True, primary_key=True) permission_name = Column(Unicode(16), unique=True, nullable=False) description = Column(Unicode(255)) groups_by_project = relation (AccessRule,collection_class=attribute_mapped_collection ('project'),backref='permission') groups=association_proxy ('groups_by_project','group',creator=_create_access_rule) class Project(DeclarativeBase): __tablename__ = 'project' project_id = Column(Integer, primary_key=True) project_name = Column(Unicode(255), nullable=False) permissions_by_group = relation (AccessRule,collection_class=attribute_mapped_collection ('group'),backref='project') permissions=association_proxy ('permissions_by_group','permission',creator=_create_access_rule) groups_by_permission = relation (AccessRule,collection_class=attribute_mapped_collection ('permission')) groups=association_proxy ('groups_by_permission','group',creator=_create_access_rule) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---