Alternative ActiveRecordProxies

The original ActiveRecordProxies have one very annoying problem. When you change a value on an object, the object is immediately saved to the database. This way you miss the best part about the Active Record pattern and it makes bindings unusable. When a user changes a value in the view, he should be able to save or reload. Saving the change immediately to the database would make that almost impossible.

At first I tried fixing ActiveRecordProxy myself, but that didn’t work. So I decided to start from scratch. The result of can be downloaded here

What’s different from the normal ActiveRecordProxy class:

  • support for save and reload.
  • minimal support for validations. If you use saveWithError, an NSError object is returned when saving fails. The userDict of this error should contain the validation errors.
  • rails like setterMethods: you can now use
    CustomerProxy.name = "test"
    instead of
    CustomerProxy.setValue_forKey("test", :name)
    (Updated: this already seems to work on normal ActiveRecordProxy objects)

To use it, put it in your load path and use it as your proxy superclass. If you’re using rucola, I will post a plugin in a couple of days. If you’re not using it yet, you should check it out.