[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Design issue for MVC and database updates
On Mar 2, 2004, at 2:16 PM, Joakim Danielson wrote:
> I have a function that stores the rows in my array (bound to
> NSArrayController) to the database with insert or update commands. The
> problem is that all old objects get updated in the database even if
> the have not been update in the GUI. So I need some kind of dirty flag
> to keep track of objects that have really changed.
One of the typical strategies is to have your model objects -- or
whatever type of context object they're fetched into -- keep track of
"snapshots." These snapshots can be dictionaries with the contents of
the original row in them. If the object's values differ from its
snapshot, the object needs saving. You also know what attributes need
saving, and can use values in the snapshot for locking (to ensure you
don't update the database with stale data).
-- Chris
--
Chris Hanson <cmh@xxxxxxxxxxxxxxxx>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training