Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERXKey.Type and NSArray#valueForKey(ERXKey) additions #567

Merged
merged 4 commits into from
May 23, 2015
Merged

ERXKey.Type and NSArray#valueForKey(ERXKey) additions #567

merged 4 commits into from
May 23, 2015

Conversation

avendasora
Copy link
Member

• Added "Operator", "NonModelAttribute", "NonModelToOneRelationship" and "NonModelToManyRelationship" Types to ERXKey and new constructors to allow them to be set when declared. (for example, by modifying the _Entity eogenerator template)

• Added valueForKey(ERXKey) to NSArray. This allows for type-safe valueForKey calls. Defaults to automatically flattens, makes distinct, and removes null values from the resulting array. This improves encapsulation and eliminates common errors caused by needing to write boilerplate code to check if the resulting array is in fact an array of arrays, or if there are null or duplicate elements.

…ey represents a Operator (@sum, @flatten, etc.) or a non-model "attribute" or "relationship".
…h options for automatic flattening, distincting, and automatic null-value removal. Greatly simplifies making type-safe calls on to-many relationships and any other NSArray.
New constructor allows setting both the localization and the Type. I also added "todo" notes regarding evaluating how the new ERXKey.Types work with ERXKeyFilter, specifically in ERRest.
@avendasora
Copy link
Member Author

This is an updated pull request based on a conversation with Henrique Prange at WOWODC.

@TriPhoenix
Copy link

These are mainly API additions, which might easy including additional keys in your EOs, right? Looks documented really well as well; any reasoning that would prohibit merging this?

@avendasora
Copy link
Member Author

The only thing that it might cause problems for would be using the new ERXKey.Type values with ERRest, as I haven't looked at how ERRest makes use of the other Types. My guess is that ERRest just wouldn't know what do do with them. I don't believe that it will break any existing code.

The NSArray#valueForKey(ERXKey) method simply overloads the valueForKey method to make it type-safe, but only if you pass it a ERXKey instead of a String. So it should not break any existing code.

@avendasora
Copy link
Member Author

Oh, and we have been using these changes for about 4 years and have not had any problems in our code at all, in fact it has eliminated a huge amount of manual, unsafe casting, and the need to filter out "null" or duplicate objects.

darkv added a commit that referenced this pull request May 23, 2015
ERXKey.Type and NSArray#valueForKey(ERXKey) additions
@darkv darkv merged commit 7774de1 into wocommunity:master May 23, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants