ObjectiveRecord icon indicating copy to clipboard operation
ObjectiveRecord copied to clipboard

Rethink mappings

Open stephencelis opened this issue 11 years ago • 4 comments

I see a few issues with the way mappings are currently implemented:

  1. They are automatically, categorically added to all NSManagedObject classes.
  2. They are coupled to the NSManagedObject+ActiveRecord category.
  3. They are unidirectional (there's no way to cast local properties back into remote ones).
  4. They are declarative (and with @kattrali's #66, the dictionary can become quickly bloated).
  5. They do a lot by default (auto-camelizing, for example).
  6. They are a memory leak (we cache every unique remote key that we check for).

Let's explore ways to address these issues.

Proposal 1: Protocol-based Mappings

One thought is that we could provide a protocol, like NSCoding, that could be used to serialize/deserialize these mappings. E.g.,

@protocol ORCoding <NSObject>
+ (NSDictionary *)dictionaryFromRemoteDictionary:(NSDictionary)dict;
- (NSDictionary *)remoteDictionaryRepresentation;
@end
  1. One would have to manually opt-in to the protocol.
  2. Looser coupling, using conformsToProtocol:.
  3. It would enforce bidirectional mappings.
  4. Method logic is more imperative.
  5. It's not included by default, so there are no defaults.
  6. No memory leaks (that are our fault, anyway)!

stephencelis avatar Mar 27 '14 03:03 stephencelis

Relates to #68.

stephencelis avatar Mar 27 '14 03:03 stephencelis

/cc @supermarin

stephencelis avatar May 29 '14 17:05 stephencelis

+1 That approach looks really nice

dzenbot avatar Jun 06 '14 15:06 dzenbot

@stephencelis I think that makes sense

supermarin avatar Jun 06 '14 16:06 supermarin