Comments (14)
According to the JSON API spec:
An endpoint MAY also support an include request parameter to allow the client to customize which related resources should be returned.
[...]GET /articles/1?include=comments HTTP/1.1
Accept: application/vnd.api+json
So, in regards to your comment above, you're request would actually look like:
GET http://localhost:3000/api/posts/9?include=author
Now, technically, we could also filter with this, so that would be:
GET http://localhost:3000/api/posts/9?include=author&filter["firstName"]=John
from loopback-component-jsonapi.
@digitalsadhu I have started on this and will most likley need help with it. I've started the branch feature/request-includes
. I have added:
- ✅ Check if the query object contains
includes
. - ✅ Check if the current method supports the parameter (e.g. DELETE, POST) should not include this param.
- ✅ Added new test for DELETE if it's included.
- ✅ If the current method does not support the parameter, JSON API spec says we must respond with a 400 error
... more to come.
from loopback-component-jsonapi.
:+1 sure thing. Just Sing out.
On Sun, 22 Nov 2015 at 02:16, Troy [email protected] wrote:
@digitalsadhu https://github.com/digitalsadhu I have started on this
and will most likley need help with it. I've started the branch
feature/request-includes. I have added:
- Check if the query object contains includes.
- Check if the current method supports the parameter (e.g. DELETE,
POST) should not include this param.- Added new test for DELETE if it's included.
... more to come.
—
Reply to this email directly or view it on GitHub
#38 (comment)
.
from loopback-component-jsonapi.
@digitalsadhu delete the branch feature/request-includes
, do a fetch, then check out the branch. I've changed a number of things. Here's my concern right now:
While I'm deleting the relationship from the attributes
property, I have to then add it back as either an array of id's (IF it's a hasMany relationship), or just as a single property for a hasOne relationship. How would I find out what the key is for the relationship?
For instance:
Has One Relationship
data: {
type: 'post',
id: 5,
attributes: {
content: 'blah',
other: 'other stuff'
authorId: 22 <-- HAS ONLY ONE
}
},
included: [
{
type: 'author',
authorId: 22
attributes: {
firstName: 'John',
lastName: 'Doe'
}
}
]
And for a hasMany...
data: {
type: 'reviewerGroup',
id: 1,
attributes: {
title: 'Reviewer Group 1',
authority: 'Bosses'
authorId: [22, 53] <--- HAS MANY
}
},
included: [
{
type: 'author',
authorId: 22
attributes: {
firstName: 'John',
lastName: 'Doe'
}
},
{
type: 'author',
authorId: 53
attributes: {
firstName: 'Joe',
lastName: 'Shmoe'
}
}
]
It wont always be "id" or "authorId" and I have no idea how to do that in Loopback lol
from loopback-component-jsonapi.
Ok I've figured it out. Have single relationship requests via include=author
. Now I need to get multiple relationship requests going, a la include=author,posts
from loopback-component-jsonapi.
@digitalsadhu @BenjaminHorn can I get one of you to CR what I've done so far. Is this the right way to go about this?
from loopback-component-jsonapi.
Cheers man, will try to take a look today/tonight
from loopback-component-jsonapi.
@tsteuwer you can always figure out everything you need to about relationships via
Model.relations for each model.
So if you are dealing with model Contract then just grab the Contract.relations object and look through it. It has the relationship type (belongsTo, hasOne, hasMany etc), the name of the foreign key and the value for it. It also gives you the from model and the to model but its important to note that the order is reversed for belongsTo.
Pretty easy to handle though, you just check the relation.type === 'belongsto' and then switch modelTo and modelFrom as @BenjaminHorn has done in his PR. Have a look in there for inspiration if you need to.
from loopback-component-jsonapi.
@digitalsadhu I did it! wooo hoo 👯 However, I can not, for the life of me, get 2 spaces working with vim. Is there any way to run a fix on the linter to autho-indent 2 spaces for me?
from loopback-component-jsonapi.
Nice one!
Haha damn indentation! There is an eslint formatted I believe so it's possible we could auto format yes. I haven't tried it but if you want you could give it a go and if it works ok add it to the project.
from loopback-component-jsonapi.
For se reason the one that comes with the project doesn't work. I've used jscs and it just works. Have you or @BenjaminHorn had a chance to check out the cr?
from loopback-component-jsonapi.
@tsteuwer Ok its Saturday night and I'm ready for open source! Will look through your code now!
from loopback-component-jsonapi.
@digitalsadhu was there anything else we need? Did you look over the code review? I can't remember the last thing that was said about this ticket
from loopback-component-jsonapi.
Merged into master as v0.11.0
Yay!
from loopback-component-jsonapi.
Related Issues (20)
- An in-range update of lint-staged is breaking the build 🚨 HOT 5
- An in-range update of loopback is breaking the build 🚨 HOT 3
- cast in updateHasManyThrough
- Update semantic-release and add additional tooling HOT 2
- An in-range update of @commitlint/config-conventional is breaking the build 🚨 HOT 1
- An in-range update of @commitlint/prompt is breaking the build 🚨 HOT 1
- An in-range update of @commitlint/cli is breaking the build 🚨 HOT 1
- Version 10 of node.js has been released
- An in-range update of loopback-datasource-juggler is breaking the build 🚨 HOT 10
- An in-range update of loopback is breaking the build 🚨 HOT 17
- [Help Wanted] exclude methods
- Example using options.meta? HOT 2
- An in-range update of supertest is breaking the build 🚨 HOT 4
- An in-range update of debug is breaking the build 🚨 HOT 4
- An in-range update of lodash is breaking the build 🚨 HOT 4
- Unable to create polymorphic relationship
- An in-range update of coveralls is breaking the build 🚨 HOT 13
- An in-range update of http-status-codes is breaking the build 🚨 HOT 3
- An in-range update of type-is is breaking the build 🚨 HOT 2
- An in-range update of body-parser is breaking the build 🚨 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-component-jsonapi.