Skip to content

Commit

Permalink
Map RepositoryRoleAssoc; fix SAWarning (back_populates)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Oct 9, 2021
1 parent 14eb3bb commit 4fdc1da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
12 changes: 11 additions & 1 deletion lib/tool_shed/webapp/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,17 @@ def __init__(self, group, role):
self.role = role


class RepositoryRoleAssociation(_HasTable):
class RepositoryRoleAssociation(Base, _HasTable):
__tablename__ = 'repository_role_association'

id = Column(Integer, primary_key=True)
repository_id = Column(Integer, ForeignKey("repository.id"), index=True)
role_id = Column(Integer, ForeignKey("role.id"), index=True)
create_time = Column(DateTime, default=now)
update_time = Column(DateTime, default=now, onupdate=now)
repository = relationship('Repository', back_populates='roles')
role = relationship('Role', back_populates='repositories')

def __init__(self, repository, role):
self.repository = repository
self.role = role
Expand Down
14 changes: 1 addition & 13 deletions lib/tool_shed/webapp/model/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
Column("create_time", DateTime, default=now),
Column("update_time", DateTime, default=now, onupdate=now))

RepositoryRoleAssociation.table = Table("repository_role_association", metadata,
Column("id", Integer, primary_key=True),
Column("repository_id", Integer, ForeignKey("repository.id"), index=True),
Column("role_id", Integer, ForeignKey("role.id"), index=True),
Column("create_time", DateTime, default=now),
Column("update_time", DateTime, default=now, onupdate=now))

Repository.table = Table("repository", metadata,
Column("id", Integer, primary_key=True),
Column("create_time", DateTime, default=now),
Expand Down Expand Up @@ -85,11 +78,6 @@
Column("rating", Integer, index=True),
Column("deleted", Boolean, index=True, default=False))

mapper_registry.map_imperatively(RepositoryRoleAssociation, RepositoryRoleAssociation.table,
properties=dict(
repository=relation(Repository),
role=relation(Role, back_populates='repositories')))

mapper_registry.map_imperatively(UserRoleAssociation, UserRoleAssociation.table,
properties=dict(
user=relation(User, backref="roles"),
Expand All @@ -108,7 +96,7 @@
order_by=desc(RepositoryMetadata.table.c.update_time)),
metadata_revisions=relation(RepositoryMetadata,
order_by=desc(RepositoryMetadata.table.c.update_time)),
roles=relation(RepositoryRoleAssociation),
roles=relation(RepositoryRoleAssociation, back_populates='repository'),
reviews=relation(RepositoryReview,
primaryjoin=(Repository.table.c.id == RepositoryReview.table.c.repository_id)),
reviewers=relation(User,
Expand Down
2 changes: 1 addition & 1 deletion test/unit/shed_unit/model/test_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ def test_relationships(self, session, cls_, repository, user, repository_metadat
class TestRepositoryRoleAssociation(BaseTest):

def test_table(self, cls_):
assert cls_.table.name == 'repository_role_association'
assert cls_.__tablename__ == 'repository_role_association'

def test_columns(self, session, cls_, repository, role):
create_time = datetime.now()
Expand Down

0 comments on commit 4fdc1da

Please sign in to comment.