Skip to content

Instantly share code, notes, and snippets.

@gcarothers
Created September 14, 2012 23:31
Show Gist options
  • Save gcarothers/3725597 to your computer and use it in GitHub Desktop.
Save gcarothers/3725597 to your computer and use it in GitHub Desktop.
mapper(Court, t.court_table, properties=dict(
district = relation(District, backref='courts'),
judges = relation(Judge, backref='court',
order_by=[t.judge_table.c.last_name,
t.judge_table.c.first_name,
t.judge_table.c.initials]),
case_count=column_property(
select([func.count(t.case_table.c.id)],
t.case_table.c.court_id==t.court_table.c.id,
), deferred=True),
unmatched_judges = relation(UnmatchedJudge, backref='court', cascade='delete',)
))
def query()
q = LexSession.query(Court)
q = q.join(Court.cases)
q = q.filter(Case.tags.any(Tag.name == 'Patent'))
q = q.order_by(Court.case_count)
return q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment