In the manual section on update_or_insert() the examples only touch on a 
situation where one field/value is given as the matching condition. I'm 
wondering what syntax needs to be used if we want to match values on more 
than one field. Extrapolating from the manual example, can I do this?
  
db.tag_records.update_or_insert(db.tag_records.name==auth.user_id, 
                                db.tag_records.tag==tag,
                                tlast_right=time_last_right)

Or should I provide a dictionary of matching fields/values (using the 
syntax that Massimo mentioned in a thread in July):
   
db.tag_records.update_or_insert({'name': auth.user_id, 'tag': tag},
                                tlast_right=time_last_right)

I actually like the latter syntax better. It's more concise and (to my 
mind) differentiates more clearly between the matching values and the 
update values.

I also wonder whether this kind of situation would be worth mentioning in 
the manual section? Assuming it's possible, this makes update_or_insert 
quite powerful.

Ian

-- 



Reply via email to