Maybe this was obvious, but I never thought I could do this kind of queries 
in DAL.  

Okay, let's say I have 2 tables:

Tags = db.define_table('tag', Field('name'))
Post = db.define_table('post', Field('title'), Field('tag', 'reference 
tag'))


Now, doing a join is easy using the query *(db.post.tag == db.tag.id)*

But if I have the following 2 tables, where a post might have many tags:

Tags = db.define_table('tag', Field('name'))
Post = db.define_table('post', Field('title'), Field('tag', 'list:reference 
tag'))

How do I select tags that occur in posts?  It turns out that this can be 
done very nice using the query:  *db.post.tag.contains( db.tag.id )*
*
*
I have used "contains", but I had thought that the argument for it must be 
a constant (e.g. a specific tag such as "news"), not something like 
db.tag.id.

Nice.

Counting tags occurrence (e.g. if you want to have a tag cloud) turns out 
to be quite simple:   *db( db.post.tag.contains(db.tag.id) 
).select(db.tag.ALL, db.tag.id.count(), groupby=db.tag.name)*

Nice!!

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to