Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web2py insert methods

Tags:

python

web2py

Web2py docs have two methods for inserting into a database

db.tbl[0] = newRow

and

db.tbl.insert(newRowAsDict)

The documentation implies that they are synonyms, but they appear to be different. For one, the insert method throws an exception if newRow contains fields that are not in the table. Also the .insert method returns the id of the added row, where the assignment doesn't.

  • Is this the intended behavior
  • How can I get the id if I use the assignment method?
  • Is the assignment method depricated?
like image 782
David Nehme Avatar asked Feb 01 '12 19:02

David Nehme


1 Answers

There is also

db.tbl.insert(**db.tbl._filter_fields(newRowAsDict))

which will filter the keys in newRowAsDict ignoring unknown fields.

like image 128
Bruno Rocha - rochacbruno Avatar answered Oct 19 '22 03:10

Bruno Rocha - rochacbruno