Clarifying:

Option 1:
> db.define_table('item',Field('tags','list:string'))
>

*Pro*:
Easy search:
tag = request.args(0)
results = db(db.item.tags.contains(tag)).select()

*Con*:
build a tag cloud
records = db(db.item.id>0).select(db.item.tags)
alltags = [] # loop thought records to populate the tags list (here you can
use reduce, list comprehension)


>
> Option 2:
> db.define_table('tag')
> db.define_table('item',Field('tags','list:reference tag'))
>

*Pro*:
build a tag clous
alltags = [ r.tag for r in db(db.tag.id>0).select('tag')]

*Con:*
Search is expensive
tag = request.args(0) # it is a string like: "book"
tag_id = db.tag(tag=tag)[0].id # or a taglist
records = db(db.item.tag.contains(tag_id)).select()


Options 3:
> db.define_table('item')
> db.define_table('tag')
> db.define_table('item_tag',Field('item'),Field('tag'))
>

*Con:*
In this case I see Tag searching and tagcloud as a expensive process.

But, certainly Massimo has a DAL trick to solve this use case in one line of
code ;)

--
Bruno Rocha
[ About me: http://zerp.ly/rochacbruno ]
[ Aprenda a programar: http://CursoDePython.com.br ]

Reply via email to