I think that this functionality is more for a ORM than the DAL.

There are certain features that the an ORM could actually work a layer
above the DAL, such as table Auditing, django-like query syntax,
many-to-many mapping/handling. Probably more.

But I always vote to keep the DAL minimal, and just that, an abstraction layer.

-Thadeus





On Sun, Mar 21, 2010 at 5:48 PM, Richard <richar...@gmail.com> wrote:
> 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.
>
>

-- 
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.

Reply via email to