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

Update Relationship data structures to follow the spec. #17

Merged

Conversation

jkongie
Copy link
Contributor

@jkongie jkongie commented Feb 10, 2016

Previously, relationships were represented by a map[string]*Object which is limited to only being able to represent 1-1 relationships. In addition, the relationship format was not adhering to the format defined by the spec. See http://jsonapi.org/format/#document-resource-object-relationships

This PR represents relationships as their own data structures, and implements a custom UnmarshalJSON to be able to handle 1-M relationships.

@jkongie jkongie changed the title Relationship data structures now follow the spec. Update Relationship data structures to follow the spec. Feb 10, 2016
type ResourceLinkage []*ResourceIdentifier

// ResourceIdentifier identifies an individual resource.
type ResourceIdentifier struct {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After seeing this, I was originally thinking we should make this a generic identifier, but for these cases an ID is required where as a for a top level data object it's not and having this be relationship specific makes sense to me.

@jkongie jkongie force-pushed the jsonapi-relationship-unmarshal branch from c443fbf to a9b7f4a Compare February 10, 2016 22:31
@derekdowling
Copy link
Owner

Thanks for implementing this! I had been waiting until this library had stabilized a bit more(which it has), and I personally had a use-case for relationships to make sure I understood how I wanted to approach them other than providing the basic stub that was there before. Other than the minor nitpick this seems great. Get that fixed, and deal with the conflict (which is from your other PR) and we'll get this merged.

@derekdowling
Copy link
Owner

Thanks, just sort out that merge conflict (should be trivial) and I'll get this in and bump the version.

Previously, relationships were represented by a map[string]*Object which 
limits us to only being able to represent 1-1 relationships. In addition,
the relationship format was not adhering to the format defined by the 
spec. http://jsonapi.org/format/#document-resource-object-relationships

This commit models relationships as their own structures, and implements 
a custom Unmarshal to be able to handle 1-M relationships.
@jkongie jkongie force-pushed the jsonapi-relationship-unmarshal branch from a9b7f4a to 2cf6c17 Compare February 11, 2016 02:08
@jkongie
Copy link
Contributor Author

jkongie commented Feb 11, 2016

No worries! Yeah I finally had a use case for relationships and noticed the issue.

I've fixed the merge conflict. Thanks for all the good work!

@derekdowling
Copy link
Owner

Awesome, thanks again. Feel free to open issues if you see any glaring architectural issues or any nice to haves that are currently missing. Not sure if you have a use case for this, but checkout: https://github.com/derekdowling/jsh-api as well.

derekdowling pushed a commit that referenced this pull request Feb 11, 2016
Update Relationship data structures to follow the spec.
@derekdowling derekdowling merged commit 101503b into derekdowling:master Feb 11, 2016
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.

2 participants