# JSRelationItem

## Overview

`JSRelationItem` represents a single criterion within a relation in the solution model. It defines how columns from the primary and foreign data sources are connected, enabling precise relationship definitions for queries and data operations. ## Functionality

JSRelationItem provides constants such as `LITERAL_PREFIX` to enable the use of literals in relation definitions. Properties like `foreignColumnName`, `primaryDataProviderID`, and `operator` allow customization of the relationship criteria. Supported operators include `=`, `!=`, `<`, `>`, `like`, and more, enabling a wide range of comparisons and queries between data sources.

Methods like `getComment` and `getUUID` assist in retrieving metadata about the relation item, such as a unique identifier or comments. These utilities enhance the traceability and documentation of relation definitions in complex solution models.

### Example

A relation item can be configured to specify relationships like:

* Linking a column from the primary table to a foreign table.
* Using literals or specific operators to define advanced criteria.

For more details, please refer to the [Relation item](https://docs.servoy.com/reference/servoycore/object-model/solution/relation/relationitem) section of this documentation.

## Constants Summarized

| Type                                                     | Name                               | Summary                                                     |
| -------------------------------------------------------- | ---------------------------------- | ----------------------------------------------------------- |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [LITERAL\_PREFIX](#literal_prefix) | Constant for using literals in solution model in relations. |

## Properties Summarized

| Type                                                     | Name                                            | Summary                                                                                             |
| -------------------------------------------------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------- |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [foreignColumnName](#foreigncolumnname)         | The name of the column from the destination table that this relation item is based on.              |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [operator](#operator)                           | The operator that defines the relationship between the primary dataprovider and the foreign column. |
| [String](/reference/servoycore/dev-api/js-lib/string.md) | [primaryDataProviderID](#primarydataproviderid) | The name of the column from the source table that this relation item is based on.                   |
| [Object](/reference/servoycore/dev-api/js-lib/object.md) | [primaryLiteral](#primaryliteral)               | Get the literal.                                                                                    |

## Methods Summarized

| Type                                                      | Name                        | Summary                                |
| --------------------------------------------------------- | --------------------------- | -------------------------------------- |
| [String](/reference/servoycore/dev-api/js-lib/string.md)  | [getComment()](#getcomment) | Returns the comment of this component. |
| [UUID](/reference/servoycore/dev-api/application/uuid.md) | [getUUID()](#getuuid)       | Returns the UUID of this component.    |

## Constants Detailed

### LITERAL\_PREFIX

Constant for using literals in solution model in relations.\
Strings must be passed as quoted value to make a distinction between string '5' and number 5.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
relation.newRelationItem(JSRelationItem.LITERAL_PREFIX + "'hello'",'=', 'mytextfield');
```

## Properties Detailed

### foreignColumnName

The name of the column from the destination table that this relation item is based on.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var relation = solutionModel.newRelation('parentToChild', 'db:/example_data/parent_table', 'db:/example_data/child_table', JSRelation.INNER_JOIN);
var criteria = relation.newRelationItem('parent_table_id', '=', 'child_table_parent_id');
criteria.primaryDataProviderID = 'parent_table_text';
criteria.foreignColumnName = 'child_table_text';
criteria.operator = '<';
```

### operator

The operator that defines the relationship between the primary dataprovider and the foreign column. Each key pair expression is evaluated using a single operator. Certain operators are only applicable to certain data types. Below is a list of all available operators and the data types for which they are applicable.

| Operator | Description                         | Data Types                                            |
| -------- | ----------------------------------- | ----------------------------------------------------- |
| =        | Equals                              | Text, Integer, Number, Datetime, UUID, Array (in)     |
| >        | Greater Than                        | Text, Integer, Number, Datetime                       |
| <        | Less Than                           | Text, Integer, Number, Datetime                       |
| >=       | Greater Than or Equal To            | Text, Integer, Number, Datetime                       |
| <=       | Less Than or Equal To               | Text, Integer, Number, Datetime                       |
| !=       | NOT Equal To                        | Text, Integer, Number, Datetime, UUID, Array (not in) |
| like     | SQL Like use with '%' wildcards     | Text                                                  |
| not like | SQL Not Like use with '%' wildcards | Text                                                  |

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var relation = solutionModel.newRelation('parentToChild', 'db:/example_data/parent_table', 'db:/example_data/child_table', JSRelation.INNER_JOIN);
var criteria = relation.newRelationItem('parent_table_id', '=', 'child_table_parent_id');
criteria.primaryDataProviderID = 'parent_table_text';
criteria.foreignColumnName = 'child_table_text';
criteria.operator = '<';
```

### primaryDataProviderID

The name of the column from the source table that this relation item is based on.

**Type**\
[String](/reference/servoycore/dev-api/js-lib/string.md)

**Sample**

```js
var relation = solutionModel.newRelation('parentToChild', 'db:/example_data/parent_table', 'db:/example_data/child_table', JSRelation.INNER_JOIN);
var criteria = relation.newRelationItem('parent_table_id', '=', 'child_table_parent_id');
criteria.primaryDataProviderID = 'parent_table_text';
criteria.foreignColumnName = 'child_table_text';
criteria.operator = '<';
```

### primaryLiteral

Get the literal.

**Type**\
[Object](/reference/servoycore/dev-api/js-lib/object.md)

**Sample**

```js
var relation = solutionModel.newRelation('parentToChild', 'db:/example_data/parent_table', 'db:/example_data/child_table', JSRelation.INNER_JOIN);
var criteria = relation.newRelationItem(JSRelationItem.LITERAL_PREFIX + "'hello'",'=', 'myTextField');
criteria.primaryLiteral = 'literal_text';
//criteria.primaryLiteral = number;
var primaryLiteral = criteria.primaryLiteral;
```

## Methods Detailed

### getComment()

Returns the comment of this component.

**Returns:** [String](/reference/servoycore/dev-api/js-lib/string.md) the comment associated with this component.

**Sample**

```js
var comment = solutionModel.getForm("my_form").getButton("my_button").getComment();
application.output(comment);
```

### getUUID()

Returns the UUID of this component.

**Returns:** [UUID](/reference/servoycore/dev-api/application/uuid.md) the UUID of this component.

**Sample**

```js
var button_uuid = solutionModel.getForm("my_form").getButton("my_button").getUUID();
application.output(button_uuid.toString());
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/solutionmodel/jsrelationitem.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
