[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Design issue for MVC and database updates
I have decided to use the model object itself to keep track of any
changes instead of doing it in the controll layer since it's more
reusable and in line with common design patterns for persistence.
I don't feel I have the need to keep track of every attribute's state
so I'll just implement a dirty flag that will tell if the object needs
updating or not.
Joakim Danielson
On 2004-03-06, at 05.39, Chris Hanson wrote:
> 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
>
>
>