i got this error for the query:

>>> items = db(db.posts.relations.category==db.categories.id).select()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/mengu/web2py/gluon/sql.py", line 1265, in __getattr__
    return dict.__getitem__(self,key)
KeyError: 'relations'


here is my table definitions:
db.define_table('posts',
    Field('title', 'string', length=200),
    Field('slug', 'string', length=200),
    Field('body', 'text'),
    Field('html', 'text'),
    Field('dateline', 'datetime', default=request.now,
writable=False),
    Field('user', db.auth_user)
)

db.define_table('comments',
    Field('post', db.posts),
    Field('author', 'string'),
    Field('body', 'string', length=500),
    Field('dateline', 'datetime', default=request.now, writable=False)
)

db.define_table('categories',
    Field('title', 'string'),
    Field('slug', 'string', length=200),
    Field('postcount', 'integer')
)

db.define_table('relations',
    Field('post', db.posts),
    Field('category', db.categories)
)


On Oct 7, 4:43 am, mdipierro <mdipie...@cs.depaul.edu> wrote:
> items = db(dd.posts.relations.category==db.categories.id).select()
> for item in items:
>     print item.posts.id,'belongs',item.categories.title
>
> On Oct 6, 8:23 pm, Mengu <whalb...@gmail.com> wrote:
>
> > massimo,
>
> > actually this wasn't what i am asking, but thank you for showing
> > another way for it. i have my controller named as "post" and i have
> > the action "view". i currently have my routes_in like the 
> > following:http://mengu.pastebin.com/m698f1726thisis working very well 
> > however
> > please let me know if this is not necessary or a proper way.
>
> > any recommendations on the query?http://mengu.pastebin.com/m111e1a47
> > i could make something like:
> > posts = db().select(db.posts.ALL)
> > postcategories = {}
> > for post in posts:
> >     postcategories[post.id] = {}
> >     for relation in post.relations.select():
> >         category = db.categories[relation.category]
> >         postcategories[post.id][category.id] = category.title
>
> > however this makes tons of queries for each post which is something i
> > really don't want.
>
> > ----
>
> > dear alvaro,
>
> > i ofcourse would like to produce the software with you, i'd enjoy
> > that. however i currently have my time very lack so i'm not working on
> > the product all the time.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to