Skip to content

Instantly share code, notes, and snippets.

@silenius
Last active August 29, 2015 14:16
Show Gist options
  • Save silenius/18190ef4912667e49b1a to your computer and use it in GitHub Desktop.
Save silenius/18190ef4912667e49b1a to your computer and use it in GitHub Desktop.
###########
# ACCOUNT #
###########
orm.mapper(Account, table['account'])
########
# POOL #
########
orm.mapper(Pool, table['pool'], properties = {
'owner' : orm.relationship(
Account,
innerjoin = True,
backref = 'pools'
),
'facilitators' : orm.relationship(
Account,
secondary = table['account_role'],
secondaryjoin = lambda : sql.and_(
Account.id == AccountRole.account_id,
AccountRole.role_id == Role.id,
Role.name == 'facilitator'
),
backref = 'facilitated_pools'
)
})
########
# ROLE #
########
orm.mapper(Role, table['role'])
################
# ACCOUNT ROLE #
################
orm.mapper(AccountRole, table['account_role'], properties = {
'human' : orm.relationship(
Account,
lazy = 'joined',
innerjoin = True,
backref = 'assigned'
),
'role' : orm.relationship(
Role,
lazy = 'joined',
innerjoin = True,
backref = 'assigned'
),
'pool' : orm.relationship(
Pool,
backref = 'assigned'
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment