Answers.Body: <p>Chaining will attempt to "guess" at the id of the chained entity. In your first example, the fetched participant record has an "event_id" and the api chaining controller passes that into the chained Event api call as the id.</p>
  
  <p>The guessing is pretty basic though. For everything else, you should specify params explicitly. You do so by using the magic "$value" notation. E.g. </p>
  
  <pre><code>CRM.api3('participant', 'get', {
    id: 12345,
    "api.ParticipantStatusType.get": {id: '$value.status_id'}
  });
  </code></pre>
  
  <p>Note that you can also use joins for this type of thing, which is generally more efficient than chaining. Check out joins in the Api explorer.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-28T22:24:21.607Z
Answers.LastActivityDate: 2017-03-28T22:24:21.607Z
Answers.UserDisplayName: Coleman
Body: <p>I read about <a href="https://docs.civicrm.org/dev/en/latest/api/chaining/" rel="nofollow noreferrer">API chaining</a> and I'm using it with <code>get</code> actions to learn more about how it works. I'm confused by the inconsistent behavior of the following two API calls: </p>
  
  <hr>
  
  <pre><code>CRM.api3('participant', 'get', 
    {"id": 12345, "api.Event.get": {} });
  </code></pre>
  
  <p>That gets a participant record and embeds the single associated event record within the results. Cool. </p>
  
  <hr>
  
  <p>But this one works differently: </p>
  
  <pre><code>CRM.api3('participant', 'get', 
    {"id": 12345, "api.ParticipantStatusType.get": {} });
  </code></pre>
  
  <p>It gets the same participant record, but embeds <em>all</em> status type records within the results. Why?</p>
  
  <hr>
  
  <p>In general, I'd like to understand what logic CiviCRM is using to filter the results of chained calls.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-28T22:21:35.613Z
Comments.Text: In your first example, did you mean to day "associated event record" instead of "associated contact record?"
Comments.UserDisplayName: Coleman
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-03-29T00:32:59.207Z
Comments.Text: Yes, thank you @Coleman I did. I've edited my question to fix this typo
Comments.UserDisplayName: Sean
Tags: <api><chaining>
Title: What is the join logic when using API chaining with action = get?
ThreadText: # What is the join logic when using API chaining with action = get?
  
  (Asked by: username_0 on 2017-03-28)
  
  I read about [API chaining](https://docs.civicrm.org/dev/en/latest/api/chaining/) and I'm using it with `get` actions to learn more about how it works. I'm confused by the inconsistent behavior of the following two API calls:
  
  ---
  
  ```
  CRM.api3('participant', 'get', 
    {"id": 12345, "api.Event.get": {} });
  
  ```
  
  That gets a participant record and embeds the single associated event record within the results. Cool.
  
  ---
  
  But this one works differently:
  
  ```
  CRM.api3('participant', 'get', 
    {"id": 12345, "api.ParticipantStatusType.get": {} });
  
  ```
  
  It gets the same participant record, but embeds *all* status type records within the results. Why?
  
  ---
  
  In general, I'd like to understand what logic CiviCRM is using to filter the results of chained calls.
  
  **Tags:** api, chaining
  
  > **Comments:**
  > **username_1**: In your first example, did you mean to day "associated event record" instead of "associated contact record?"  
  > **username_0**: Yes, thank you @username_1 I did. I've edited my question to fix this typo  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-28. Score: 16 | Accepted answer
  
  Chaining will attempt to "guess" at the id of the chained entity. In your first example, the fetched participant record has an "event\_id" and the api chaining controller passes that into the chained Event api call as the id.
  
  The guessing is pretty basic though. For everything else, you should specify params explicitly. You do so by using the magic "$value" notation. E.g.
  
  ```
  CRM.api3('participant', 'get', {
    id: 12345,
    "api.ParticipantStatusType.get": {id: '$value.status_id'}
  });
  
  ```
  
  Note that you can also use joins for this type of thing, which is generally more efficient than chaining. Check out joins in the Api explorer.
  
  
  ---
  
  