API formation for side loading only required associated data to ember data

扶醉桌前 提交于 2019-12-26 00:49:17

问题


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)


回答1:


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



来源:https://stackoverflow.com/questions/52751907/api-formation-for-side-loading-only-required-associated-data-to-ember-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!