Skip Headers

# getTable

Previous

Next

The `getTable` method returns an expression that represents an unmapped table in the database. This expression provides a context from which to retrieve an unmapped field when you use the `getField` method.

Example: Using getTable and getField Together illustrates how to combine both `getField` and `getTable` in the same expression.

Using getTable and getField Together

    builder.getTable("[TABLE_NAME]").getField("[FIELD_NAME]").equal("[ARGUMENT]");

A common use for the `getTable` and `getField` methods is to retrieve information from a link table (or reference table) that supports a many-to-many relationship.

Example: Using a Data Query Against a Link Table reads a many-to-many relationship that uses a link table and also checks an additional field in the link table. This code combines an object query with a data query, using the employee's manager as the basis for the data query. It also features parameterization for the project ID.

Using a Data Query Against a Link Table

    ExpressionBuilder emp = new ExpressionBuilder();
    Expression manager = emp.get("manager");
    Expression linkTable = manager.getTable("PROJ_EMP");
    Expression empToLink = emp.getField("EMPLOYEE   .EMP_ID").equal(linkTable.getField("PROJ_EMP.EMP_ID");
    Expression projToLink = linkTable.getField("PROJ_EMP
      .PROJ_ID").equal(emp.getParameter("PROJECT.PROJ_ID"));
    Expression extra = linkTable.getField("PROJ_EMP.TYPE").equal("W");
    query.setSelectionCriteria((empToLink.and(projToLink)).and(extra));