On Tue, Oct 6, 2009 at 10:57 PM, Mengu <[email protected]> wrote:
>
> alvaro, i guess i cannot add relations to my posts table as Field
> ('relations', db.relations) since the relations table is not defined
> before the posts table.
>
I don't think you need this in your posts table (cross references), but in
any case, the way that you would specify a forward reference is thus:
...
Field( 'relations_id', 'reference relations')
...
>
> before using the current query, i have tried the query that you guys
> provided. my main problem with that query is that it selects all the
> posts in the relations table and each table is selected more than
> once. so i need some guidance here to print the post title and all of
> its categories.
>
> thanks.
>
>
> On Oct 7, 6:22 am, mdipierro <[email protected]> wrote:
> > Sorry I had to guess. Now that I know the tables:
> >
> > items = db(db.posts.id==db.relations.post)
> > (db.relations.category==db.categories.id).select()
> >
> > On Oct 6, 9:36 pm, Mengu <[email protected]> wrote:
> >
> > > 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 <[email protected]> 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 <[email protected]> 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/m698f1726thisisworkingvery 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---