would it be sensible for the web2py DAL to handle this automatically?
On Mar 22, 2:55 am, "mr.freeze" <nat...@freezable.com> wrote: > Something like this?: > > existing = db(db.person.id==desired_id).select().first() > incoming = [f for f in request.vars.keys() if f in > db.person.fields] > changes = dict([(f,request.vars[f]) for f in incoming if > existing[f] != request.vars[f] ]) > if changes: existing.update_record(**changes) > > On Mar 21, 10:22 am, Matthew <matthew.g.nor...@gmail.com> wrote: > > > Thank you for your quick reply. > > > In my example, I provided only field for simplicity. In reality, you > > could have 20 fields to check against. Would I have to check all of > > them manually, or is this a cleaner way? > > > Thanks again! > > > On Mar 21, 10:45 am, "mr.freeze" <nat...@freezable.com> wrote: > > > > existing = db(db.person.id==desired_id).select().first() > > > if existing and existing.name != request.vars.name: > > > existing.update_record(name=request.vars.name) > > > > On Mar 21, 9:38 am, Matthew <matthew.g.nor...@gmail.com> wrote: > > > > > Is there a clean way to update a record only if it is different than > > > > the proposed changes? > > > > > For example, I have a person in the table 'person' whose name is > > > > 'Pete'. To update his name: > > > > > desired_id = 5 > > > > db(db.person.id == desired_id).update(name='Pete') > > > > > Update is executed, even though his name did not change. What's the > > > > cleanest way to not do the update if the record's fields have not > > > > changed? > > > > > Thanks, > > > > Matthew -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.