ORM Question

58 views
Skip to first unread message

Pai

unread,
Mar 6, 2008, 12:25:48 PM3/6/08
to web2py Web Framework
How do you say something like..

select id from movie where id not in (select distinct movieid from
movierate where userid='xxx')

in orm??

i tried

db(db.movie.id.belongs(db(db.movierate.userid==session.user_id)._select(db.movierate.movieid)).select(db.movie.id)

just to get all the movie that has been rated but it end up giving the
same movies multiple times.

~ in front of db.movie.id.belongs(...) doesn't do 'not' belongs..

any idea??

Pai





Massimo Di Pierro

unread,
Mar 6, 2008, 12:37:28 PM3/6/08
to web...@googlegroups.com
There is not "does not belong" (and there should be) so you have to do

db('NOT %s' % db.movie.id.belongs(....)).select()

distinct is done with following select option

groupby=db.movie.id

Massimo

Reply all
Reply to author
Forward
0 new messages