problem with custom primarykey

99 views
Skip to first unread message

Vincenzo Ampolo

unread,
Jul 8, 2012, 7:52:42 PM7/8/12
to web...@googlegroups.com
Hi,

I'm trying to set up primary keys for the table 'ratings' described as :

db.define_table('users',
Field('name'),
Field('email'),
Field('imdb_id', 'integer')
)

db.define_table('movies',
Field('imdb_id', 'integer')
)

db.define_table('ratings',
Field('iuser', db.users, requires =
IS_IN_DB(db,'users.id',db.users._format)),
Field('imovie', db.movies, requires =
IS_IN_DB(db,'movies.id',db.movies._format)),
Field('rating', 'double'),
primarykey=['iuser', 'imovie'],
)

Reading the web2py book I saw:
http://web2py.com/books/default/chapter/29/6#Legacy-databases-and-keyed-tables

Referenceing fields must use the reference tablename.fieldname format.

But what does it mean? I tried many combinations like :
['iuser.id', 'imovie.id']
['users', 'movies']
['users.id', 'movies.id']

But none of them work. I end up with two errors: The first one states
that i should use fields defined in the ratings table and the second one
is that the given string cannot be splitted at the dot.

What am i doing wrong?
--
Vincenzo Ampolo
http://vincenzo-ampolo.net
http://goshawknest.wordpress.com

Andrew

unread,
Jul 9, 2012, 3:48:50 AM7/9/12
to web...@googlegroups.com
See the dot point
Keyed table can only refer are to other keyed tables.
You have a mixture of Id fields and keys.

Vincenzo Ampolo

unread,
Jul 9, 2012, 12:13:21 PM7/9/12
to web...@googlegroups.com
I've fixed my issue using a unique index. I just wanted to make sure
that there were no (iuser, imovie) duplicate tuples in my datased.

Is somebody working in implementing indexes in DAL?

Massimo Di Pierro

unread,
Jul 9, 2012, 6:25:46 PM7/9/12
to web...@googlegroups.com
No. I am not sure this belongs to DAL but if you have ideas, feel free to share them.
Reply all
Reply to author
Forward
0 new messages