Ember.js 如何使用余烬数据获取parentRecord id

Ember.js 如何使用余烬数据获取parentRecord id,ember.js,ember-data,Ember.js,Ember Data,根据在ember数据中实现的测试,当我们从hasMany关系请求子记录时,存储会生成一个get-to-child-resources url并发送所需子资源的ID test("finding many people by a list of IDs", function() { store.load(Group, { id: 1, people: [ 1, 2, 3 ] }); var group = store.find(Group, 1); equal(ajaxUrl, un

根据在ember数据中实现的测试,当我们从hasMany关系请求子记录时,存储会生成一个get-to-child-resources url并发送所需子资源的ID

test("finding many people by a list of IDs", function() {
  store.load(Group, { id: 1, people: [ 1, 2, 3 ] });

  var group = store.find(Group, 1);

  equal(ajaxUrl, undefined, "no Ajax calls have been made yet");

  var people = get(group, 'people');

  equal(get(people, 'length'), 3, "there are three people in the association already");

  people.forEach(function(person) {
    equal(get(person, 'isLoaded'), false, "the person is being loaded");
  });

  expectUrl("/people");
  expectType("GET");
  expectData({ ids: [ 1, 2, 3 ] });
如何发送父记录(组)的id?我的服务器需要这个id来检索篡改的记录。它需要像这样的东西:

expectData({groud_id: the_group_id, ids: [1,2,3] })

您无法传递额外的参数,到今天为止,资源应该是“根”的。这意味着,在您的
config/routes.rb
中:

resources :organization
resources :groups
resources :people
乍一看,您可能会感到害怕,“天哪,我正在失去数据隔离…”,但事实上,这种隔离最终通常由关系连接提供,从拥有嵌套内容的祖先开始。无论如何,这些连接可以由ORM以(合理的)价格执行,以声明祖先中的任何叶资源

假设您使用的是RoR,您可以在模型中添加关系快捷方式,以确保嵌套资源的隔离(请注意,
有许多…到…
,这是很重要的内容):

(在这里,为了更清晰,将返回所有现有实例集。应根据请求的ID对结果进行筛选…)

class Organization < ActiveRecord::Base
  has_many :groups
  has_many :people, through: groups
end

class Group < ActiveRecord::Base
  has_many :people
end
class GroupsController < ApplicationController
  def index
    render json: current_user.organization.groups.all, status: :ok
  end
end

class PeopleController < ApplicationController
  def index
    render json: current_user.organization.people.all, status: :ok
  end
end