Querying multiple tables with joins
From DreamFactory
Line 1: | Line 1: | ||
− | + | === Tutorial === | |
GET related records in multiple tables from a SQL database. Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL. | GET related records in multiple tables from a SQL database. Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL. | ||
Line 5: | Line 5: | ||
Note that passing * as the 'related' parameter will return data for all related tables. | Note that passing * as the 'related' parameter will return data for all related tables. | ||
− | + | === API Endpoint === | |
<pre>GET https://{url}/api/v2/{api_name}/_table/{table_name}?related={foreign_key_field}</pre> | <pre>GET https://{url}/api/v2/{api_name}/_table/{table_name}?related={foreign_key_field}</pre> | ||
− | + | === API Docs Screenshot === | |
[[File:Swagger-related.png|1000px]] | [[File:Swagger-related.png|1000px]] | ||
− | + | === Example - Fetch contact and contact_info_by_contact_id records in one API call. === | |
* Table name: contact | * Table name: contact | ||
Line 19: | Line 19: | ||
* Request URL: <pre>https://foo.com/api/v2/db/_table/contact?related=contact_info_by_contact_id</pre> | * Request URL: <pre>https://foo.com/api/v2/db/_table/contact?related=contact_info_by_contact_id</pre> | ||
− | + | === Example - Fetch contact, contact_info_by_contact_id, and contact_group_relationship_by_contact_id records in one API call. === | |
* Table name: contact | * Table name: contact | ||
Line 25: | Line 25: | ||
* Request URL: <pre>https://foo.com/api/v2/db/_table/contact?related=contact_info_by_contact_id%2C%20contact_group_relationship_by_contact_id</pre> | * Request URL: <pre>https://foo.com/api/v2/db/_table/contact?related=contact_info_by_contact_id%2C%20contact_group_relationship_by_contact_id</pre> | ||
− | + | === Example - Fetch contact and all related records by foreign key in one API call. === | |
* Table name: contact | * Table name: contact | ||
* Related parameter in API call: <pre>*</pre> | * Related parameter in API call: <pre>*</pre> | ||
* Request URL: <pre>https://foo.com/api/v2/db/_table/contact?related=*</pre> | * Request URL: <pre>https://foo.com/api/v2/db/_table/contact?related=*</pre> |
Revision as of 17:52, 3 February 2016
Contents
- 1 Tutorial
- 2 API Endpoint
- 3 API Docs Screenshot
- 4 Example - Fetch contact and contact_info_by_contact_id records in one API call.
- 5 Example - Fetch contact, contact_info_by_contact_id, and contact_group_relationship_by_contact_id records in one API call.
- 6 Example - Fetch contact and all related records by foreign key in one API call.
Tutorial
GET related records in multiple tables from a SQL database. Try these examples in the 'API Docs' tab of the DreamFactory Admin Console or from the command line with cURL.
Note that passing * as the 'related' parameter will return data for all related tables.
API Endpoint
GET https://{url}/api/v2/{api_name}/_table/{table_name}?related={foreign_key_field}
API Docs Screenshot
Example - Fetch contact and contact_info_by_contact_id records in one API call.
- Table name: contact
- Related parameter in API call:
contact_info_by_contact_id
- Request URL:
https://foo.com/api/v2/db/_table/contact?related=contact_info_by_contact_id
Example - Fetch contact, contact_info_by_contact_id, and contact_group_relationship_by_contact_id records in one API call.
- Table name: contact
- Related parameter in API call:
contact_info_by_contact_id, contact_group_relationship_by_contact_id
- Request URL:
https://foo.com/api/v2/db/_table/contact?related=contact_info_by_contact_id%2C%20contact_group_relationship_by_contact_id
- Table name: contact
- Related parameter in API call:
*
- Request URL:
https://foo.com/api/v2/db/_table/contact?related=*