Skip to content

Using session.Find with a composite key

Jeremy Swartwood edited this page Mar 17, 2015 · 2 revisions

#Overview

The session.Find works on keys (Primary or other Unique keys). However, to work on a composite key (more than 1 column key), you need to specify the column names and the associated values in a JSON format.

Find Command Syntax:

session.find(<Constructor>, <key[s]>, <callback method>, [...]);
session.find(<Projection>, <key[s]>, <callback method>, [...]);
session.find(<tableName>, <key[s]>, <callback method>, [...]);

Where [...] indicates other values you want to pass on directly to the callback method.

Single Column Key

Example with single column key:

session.find(Employee, '110183', onFind);

Composite Key

To pass the value for a composite key, use JSON format.

Example with Composite key:

To find employee 110183 who is the manager for the department d003 the following code works:

session.find(deptMan.DepartmentManager, {dept_no:'d003',emp_no:'110183'}, onFind);

The trick is formatting the keys like this: {dept_no:'d003',emp_no:'110183'}

Or rather {column1Name:'Value1',Column2Name,'Value2'}

Clone this wiki locally