Hard to say what's going on. Just loading the grid doesn't do any writing to the database, so something else must be happening. Can you produce a minimal app that replicates this behavior with SQLite?
Anthony On Friday, May 3, 2013 10:15:43 AM UTC-4, Tim Richardson wrote: > > > > On Friday, 3 May 2013 23:59:51 UTC+10, Anthony wrote: >> >> How did the record get created to begin with? Did it start with a >> cm_patient_id value of 0? Are you sure you committed your change when using >> the database management tool? > > > This works: > I open up the grid in web2py, and click on the button "Match Patients" > which invokes the controller match_patient, allowing me to edit that record. > I match the patient, which updates the foreign key cm_patient_id via the > requires=IS_IN_DB. > The calculated fields works too. > > So if I go to Management Studio and look at the table, I can see the > foreign key (an integer) and the the calculated field (a string). So I'm > definitely convinced that the edit of the record in the SQLFORM of > match_patient() is committing. > > Going back to web2py, if I refresh the SQLFORM.grid or enter it again, at > that point the table is reset. The foreign key is set to 0, which is the > default value, and the calculated field is set to NULL. Other fields are > unaffected. Is it a database migration? (migrate = False in the model). The > fact the the calculated field is set to NULL is probably not as interesting > as the resetting of cm_patient_id. > > (if I change the table definition in Management Studio so that the default > value is 99, then opening the controller which displays the grid puts 99 in > every row (inspected via Management Studio) > Then I can edit the definition to make the default value 55, refresh the > controller and I get 55 in every row. > So the grid is wiping out that field and the database replaces it with the > default value. > I guess there is something wrong with my table definition. > > > This is what I have right now (I've disabled the compute) > > db_vciadmin = DAL('mssql://tim:xxx@vci-win2003\hcnsql07/vciadmin', > lazy_tables=True,pool_size=10) > . > . > . > > > > db_vciadmin.define_table("web_form_1te", > Field("patient_details_id",'integer',unique=True), > Field("date_submitted","date"), > Field("first_name","string"), > Field("surname","string"), > Field("dob","date"), > #Field("cm_patient_id","reference cm_patient"), > Field("cm_patient_id","integer"), > #Field("patient","string", compute=lambda r: > patient_name(r['cm_patient_id'])), > Field("patient","string"), > format='%(first_name)s %(surname)s', > migrate=False > ) > > > > > > > > -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.