What you have is correct in the sense that you want to do something that
update_or_insert cannot do. As I look at it I realize update_or_insert is a
little useless as implemented. I just changed it in trunk.
Get the latest trunk and try this:
db.foo.update_or_insert({'user_id':1},haz='a')
this updates haz if a record with user_id==1 exists.
On Tuesday, 31 July 2012 10:10:36 UTC-5, Alec Taylor wrote:
>
> I want only one value stored per unique user, but using the
> `update_or_insert()` function is storing multiple values:
>
> db.define_table(
> 'foo',
> Field('haz', notnull=True, unique=True, requires=IS_IN_SET(['a', 'b',
> 'c'])),
> Field('user_id', db.auth_user, unique=True))
>
> db.foo.update_or_insert(haz='a', user_id=1)
> db.foo.update_or_insert(haz='b', user_id=1)
> db.foo.update_or_insert(haz='c', user_id=1)
>
>
> It should only have one record at the end of this, with haz='c' and
> user_id=1. Instead, it provides 3 records.
>
> How do I get this to work properly?
>
> Thanks for all suggestions,
>
> Alec Taylor
>
--