DAL has having

8 views
Skip to first unread message

mdipierro

unread,
Nov 7, 2008, 3:35:55 PM11/7/08
to web2py Web Framework
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'}>

Yarko T

unread,
Nov 7, 2008, 3:56:49 PM11/7/08
to web...@googlegroups.com
explain more..... I see having.itemtype.count() > 1 returns the LAST items of type 'blog' and 'dig'  (item 'link' has only one, so doesn't meet the 'having' criteria).

But why does it only return one of these items (and not all)?

mdipierro

unread,
Nov 7, 2008, 4:07:28 PM11/7/08
to web2py Web Framework
because that is what group by in sql does.

On Nov 7, 2:56 pm, "Yarko T" <yark...@gmail.com> wrote:
> explain more..... I see having.itemtype.count() > 1 returns the LAST items
> of type 'blog' and 'dig' (item 'link' has only one, so doesn't meet the
> 'having' criteria).
> But why does it only return one of these items (and not all)?
>
Reply all
Reply to author
Forward
0 new messages