Inspired by this:
http://www.eflorenzano.com/blog/post/secrets-django-orm/
I implemented "having" in the web2py DAL. In trunk only. Here is the
web2py way:
>>> db=SQLDB()
>>> db.define_table('TumbleItem',SQLField('title'),SQLField('item_type'))
>>> for t,p in [('Blog Post 1','blog'),('Blog Post 2','blog'),('Blog Post 3','blog'),('ArticleDug 1','digg'),('Article Dugg 2','digg'),('Link Saved','link')]: db.TumbleItem.insert(title=t,item_type=p)
>>> for row in db().select(db.TumbleItem.ALL,groupby=db.TumbleItem.item_type,having=db.TumbleItem.item_type.count()>1): print row
Output:
<SQLStorage {'update_record': <function <lambda> at 0x25ed4f0>,
'item_type': 'blog', 'id': 3, 'title': 'Blog Post 3'}>
<SQLStorage {'update_record': <function <lambda> at 0x25ed6f0>,
'item_type': 'digg', 'id': 5, 'title': 'Article Dugg 2'}>