Description
Hey,
I think this spec looks pretty awesome so far but I'd love some light to be shed on the many-to-many links.
These are, at least in a relational db like postgresql and in rails for instance, represented as a "join model". And a lot of the times when using said join model it is very useful to be able to add data to that model. One thing that often occurs in my apps are for instance a position or connection specific information.
Let me try to illustrate with a small example with some pseudo schema DSL:
Project
- id
- name
- images (through project_images)
Image
- id
- caption
- url
- projects (through project_images)
ProjectImage
- project_id
- image_id
- caption (project specific)
- position
So in this case I can easily have the results of the join query ordered by a custom position and also be able to override the image caption on a project basis.
And when looking at the JSON API it looks like a things like this could be implemented if i GET the /projects/:id/links/images
endpoint. But the examples show that it's not possible right now.
Ideally I'd love to be able to get a result set like this if I also append ?include=project,images
to the links endpoint:
{
data: [
{
type: 'project_images',
id: 1,
position: 0,
caption: 'I wrote this for "A project"',
links: {
linkage: {
project: {type: 'projects', id: 1},
image: {type: 'images', id: 1}
}
}
}
...
],
included: [
{
type: 'projects',
id: 1,
name: 'A project'
},
{
type: 'images',
id: 1,
caption: 'I wrote this for myself'
}
...
]
}
When I write this example I realise the problem: that we would probably not want to actually expose the join model as it's not a "resource". But how else could the information kept in the join model be accessed? Or is there a better way that I'm missing to solve this particular problem?