Git Product home page Git Product logo

Comments (2)

jrdnull avatar jrdnull commented on May 4, 2024

I'm trying to figure the same thing out at the moment, this is fairly old so unsure if this is still a problem for you but you could provide the links by implementing JSONAPIRelationshipLinks as shown in the examples:

func (blog Blog) JSONAPIRelationshipLinks(relation string) *jsonapi.Links {
	if relation == "posts" {
		return &jsonapi.Links{
			"related": fmt.Sprintf("https://example.com/blogs/%d/posts", blog.ID),
		}
	}
	if relation == "current_post" {
		return &jsonapi.Links{
			"related": fmt.Sprintf("https://example.com/blogs/%d/current_post", blog.ID),
		}
	}
	return nil
}

this won't give you the data field though (id/type) as you like, but should still comply with the spec as I understand it as it states it must include at-least one: http://jsonapi.org/format/#document-resource-object-relationships so the links should be enough to satisfy it and give the consumer a location to find it or the hint that it might be able to be specified with the include param.

Ideally I'd also like to include the id and type as well, but don't see a way of doing that currently.

from jsonapi.

DenLilleMand avatar DenLilleMand commented on May 4, 2024

I suppose the solution, if you have e.g. a one-to-many relationship is to create a struct named after the relationship, which implements the JSONAPILinks method which returns the self and related links, it should then only contain the primary,<name_of_relationship> and should be filled out by separate db calls which fetch only the relationship IDs.

This library sells it self on the fact that you shouldn't create glue structs though, so there should be an proposal to get this behavior built into the tags etc. Nevertheless, you still have to built some code that only fetches the IDs of a specific relationship.

EDIT: never mind, that doesn't work either. It puts the links object inside of the data.

from jsonapi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.