问题描述
请检查我以前的问题 ember js-从仅在需要时后端 与上述问题有关,我需要在Ruby中对API组的帮助(JSON格式:jsonapi.org) 如何形成仅用于侧层students.records的API,并与Ember-Data商店(学校和学生)中已经可用的数据链接
推荐答案
基于另一个问题的评论,我认为您想要
之类的东西GET /api/students?include=records
但是您需要过滤到学校,这是应用程序特定代码可以进入的地方,因为{ json:api }不决定如何进行过滤
但是,我已经使用过: https://github.com/activerecord-hackery/ransack-hackery/ransack 成功
所以,您的新查询将是:
GET /api/students?include=records&q[school_id_eq]=1
让所有学生及其记录具有ID 1
然后在Ember中进行此查询:
store.query('student', { include: 'records', q: { ['school_id_eq']: 1 } });
希望这会有所帮助
问题描述
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)
推荐答案
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