Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Rethink mappings #88

@stephencelis

Description

@stephencelis

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 Support generic value transformation in mappings #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)!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions