侧面加载的API格式仅将所需的关联数据添加到余烬数据 [英] API formation for side loading only required associated data to ember data

查看:79
本文介绍了侧面加载的API格式仅将所需的关联数据添加到余烬数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请检查我之前的问题 EMBER JS-从中获取关联的模型数据后端(仅在需要时) 与上述问题相关,我需要在Rails上的ruby中API形成方面的帮助(JSON格式:jsonapi.org) 如何形成仅用于侧面加载students.records的API,以及如何链接余烬数据存储中已有的数据(学校和学生)

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

但是您需要将其过滤到学校,因为{ json:api }并不指示应该如何进行过滤,这是可以输入特定于应用程序的代码的地方

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

但是,我已经使用了它: https://github.com/activerecord-hackery/ransack 成功

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

获取ID为1的学校的所有学生及其记录

to get all students and their records for the school with id 1

,然后在ember中进行此查询:

and then to make this query in ember:

store.query('student', {
  include: 'records',
  q: {
    ['school_id_eq']: 1
  }
});

希望这会有所帮助

这篇关于侧面加载的API格式仅将所需的关联数据添加到余烬数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆