# Make relation programmatically on the temporary table

**URL:** <https://forum.servoy.com/t/make-relation-programmatically-on-the-temporary-table/16876>\
**Category:** Classic Servoy\
**Created:** [December 26, 2012, 2:50am UTC](https://forum.servoy.com/t/make-relation-programmatically-on-the-temporary-table/16876 "2012-12-26T02:50:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonid](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@leonid](https://forum.servoy.com/u/leonid)\
**Post date:** [December 26, 2012, 2:50am UTC](https://forum.servoy.com/t/make-relation-programmatically-on-the-temporary-table/16876/1 "2012-12-26T02:50:44Z")

</div>

I create empty dataSet and fill after data. I have only 2 fields itemid and parentid.  
I try to setup relation between 2 fields. It works if I use global variable on left side and failed if I use actual Field . Why? Here the last part of code  
var rel = solutionModel.newRelation(‘myRelation’, ItemDataSource, ItemDataSource, JSRelation.INNER\_JOIN);  
rel.initialSort = ‘itemid asc’ // ‘sortseq asc’;  
rel.allowCreationRelatedRecords = true;  
rel.allowParentDeleteWhenHavingRelatedRecords = true;

this part works:  
rel.newRelationItem(‘scopes.globals.glb\_item\_id’, ‘=’, ‘parent\_id’);

this part failed  
rel.newRelationItem(‘item\_id’, ‘=’, ‘parent\_id’);

The code doesnot bomb,just myRelation not created  
How to setup relation programmatically on the temporary tables(memory buffered dataset).

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [January 2, 2013, 12:24pm UTC](https://forum.servoy.com/t/make-relation-programmatically-on-the-temporary-table/16876/2 "2013-01-02T12:24:24Z")

</div>

Leonid,

That should work, here is a small code snippet that shows it works.

```auto
	var ds = databaseManager.createEmptyDataSet(0,['a', 'b'])
	ds.addRow([1, 100])
	ds.addRow([100, 123])
	var uri = ds.createDataSource('mydata', [JSColumn.INTEGER, JSColumn.INTEGER]);
	var rel = solutionModel.newRelation('rel',uri,uri,JSRelation.INNER_JOIN)
	rel.newRelationItem('b','=','a')
	var fs = databaseManager.getFoundSet(uri)
	fs.loadAllRecords()
	application.output(fs.getRecord(1)['rel'].b) // prints 123

```

Rob

---

<div class="post-metadata">

**Author:** ![leonid](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@leonid](https://forum.servoy.com/u/leonid)\
**Post date:** [January 3, 2013, 2:14am UTC](https://forum.servoy.com/t/make-relation-programmatically-on-the-temporary-table/16876/3 "2013-01-03T02:14:38Z")

</div>

Thanks,it works.
