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

Identity attribute relationships #15

Closed

Conversation

ManueGE
Copy link

@ManueGE ManueGE commented Apr 18, 2015

If your JSON has the relationships by referencing the identity attribute instead of by nesting JSONs, you can take advantage of the identityAttributeRelated attribute. For example, if your JSON NSDictionary is:

NSDictionary *batman = @{
      @"id": @"1",
      @"name": @"Batman",
      @"publisher": @"1"
      }

you may not want Groot to serialize this dictionary by setting 1 to the Publisher relationship, but by assigning it with the Publisher object which has 1 as its identityAttribute value. You accomplish that by associating the identityAttribute key with true (or any other positive boolean value) in the entity user info dictionary:

Entity User Info

This way, Groot will search in the publisher entity for a entry with the given identity attribute. If it is found, it will assign this entry as the Publisher object of the Character; if it doesn't Groot will create a placeholder Publisher entry with this value for the identity attribute. This placeholder object would be filled eventually if the new data is provided.

Note: To make this feature works, you must always to use the merge methods instead of the insert ones.

Manuel G-Estañ added 6 commits February 28, 2015 14:16
@ManueGE
Copy link
Author

ManueGE commented Apr 18, 2015

Includes test cases in the GRTIdentityRelatedSerializationTests class.

@gonzalezreal
Copy link
Owner

This is a very interesting feature. Groot is currently being reimplemented using Swift. Let me know if you'd be interested in providing this feature in that branch as well.

@ManueGE
Copy link
Author

ManueGE commented Apr 21, 2015

Sure, I'll implement it when I have some time.

@ManueGE
Copy link
Author

ManueGE commented Apr 27, 2015

I've done it.

Any comments are welcome.

@gonzalezreal
Copy link
Owner

Thanks! I will look into it as soon as I have some spare time.

@gonzalezreal
Copy link
Owner

There has been a lot of internal changes for milestone 1.0, so this PR is kind of updated. In any case your contribution was very useful and effectively has been the seed for #26. Thanks a lot!

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.

None yet

2 participants