Please check my previous question
EMBER JS - Fetch associated model data from back-end only when required
Related to the above question I need help on API formation in ruby on rails(JSON format: jsonapi.org)
how to form the API for sideloading only students.records
and link with data already available in ember-data store (school and students)
Asked
Active
Viewed 57 times
-1

NullVoxPopuli
- 61,906
- 73
- 206
- 352

nagasundaram I
- 139
- 1
- 3
-
could you add some details about the types of data you are wanting in what scenarios? (like example payloads, etc) – NullVoxPopuli Oct 11 '18 at 09:40
1 Answers
0
based on the comments in the other question, I think you're wanting something like
GET /api/students?include=records
But you need that filtered to a school, which is where application-specific code can come in, as { json:api }
does not dictate how filtering should happen
but, I've used this: https://github.com/activerecord-hackery/ransack with much success
So, your new query would be something like:
GET /api/students?include=records&q[school_id_eq]=1
to get all students and their records for the school with id 1
and then to make this query in ember:
store.query('student', {
include: 'records',
q: {
['school_id_eq']: 1
}
});
hope this helps

NullVoxPopuli
- 61,906
- 73
- 206
- 352
-
Thank you so much need one more clarification on the linking part From the API response do I need to link the records to each student or ember and json API will take care of that or Do I need to specifically format the API for linking – nagasundaram I Oct 11 '18 at 10:06
-
ember-data should take care of that for you. all the `records` will show up in the `included` array in the `{ json:api }` payload. All you need to do is specify in your models that a student hasMany records, and a record belongsTo a student (that'd need to be specified on both frontend and backend) – NullVoxPopuli Oct 11 '18 at 10:08
-
@NullVoxPopuli JSON API specification reserves `filter` query param for filtering. I think it does not forbid to use another query param (like `q` in your answer) but using `filter` is more inline with spec IMO. – jelhan Oct 11 '18 at 21:24
-