How to get parentRecord id with ember data

According to the test implemented in ember-data, when we request child records from the hasMany relationship, the store receives a GET for the URLs of the child resources and sends the identifiers of the necessary child resources.

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 ] });

How can I also send the parent record identifier (Group)? My server needs this identifier to retrieve the entered record. He needs something like:

expectData({groud_id: the_group_id, ids: [1,2,3] })
0
source share
1 answer

You have no way to pass additional parameters, and today it is expected that the resources will be "at the root". This means that in config/routes.rb:

resources :organization
resources :groups
resources :people

: "OMG, ...", , , , , . , ORM () , - .

, RoR, ( has_many ... through ...):

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

class Group < ActiveRecord::Base
  has_many :people
end

, ( Organization):

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

( . ...)

+1

All Articles