I'm using editor with node.js. How to filter on an mjoin the joined table?
I have this mjoin:
let editor = new Editor( db, 'glossary', 'id' )
.fields(
new Field( 'glossary.id' ),
new Field( 'glossary.field_name' )
)
.join(
new Mjoin('groups')
.link('glossary.id', 'glossary_groups.glossary_id')
.link('groups.id', 'glossary_groups.group_id')
.order('name asc')
.fields(
new Field('id')
.options(new Options()
.table('groups')
.value('id')
.label('name')
),
new Field('name')
)
)
Which renders:
data [ {…}, {…}, {…}, … ]
0 Object { DT_RowId: "row_51", glossary: {…}, groups: [] }
DT_RowId "row_51"
glossary Object { id: 51, … }
id 51
field_name "Field Name 51"
groups []
1 Object { DT_RowId: "row_226", glossary: {…}, groups: […] }
DT_RowId "row_226"
glossary Object { id: 226, … }
id 226
field_name "Field Name 226"
groups [ {…}, {…} ]
0 Object { id: 59, name: "Group 59", … }
1 Object { id: 60, name: "Group 60", … }
2 Object { DT_RowId: "row_147", glossary: {…}, groups: [] }
DT_RowId "row_147"
glossary Object { id: 147, … }
id 147
field_name "Field Name 147"
groups []
3 Object { DT_RowId: "row_149", glossary: {…}, groups: […] }
DT_RowId "row_149"
glossary Object { id: 149, … }
id 149
field_name "Field Name 149"
groups [ {…} ]
0 Object { id: 59, name: "Group 59", … }
How can I filter (OR) on the 'groups' table e.g. [ '59', '60' ]?
// getData.selectGroupID:
// [ '59', '60' ]
So result:
data [ {…}, {…}, {…}, … ]
1 Object { DT_RowId: "row_226", glossary: {…}, groups: […] }
DT_RowId "row_226"
glossary Object { id: 226, … }
id 226
field_name "Field Name 226"
groups [ {…}, {…} ]
0 Object { id: 59, name: "Group 59", … }
1 Object { id: 60, name: "Group 60", … }
3 Object { DT_RowId: "row_149", glossary: {…}, groups: […] }
DT_RowId "row_149"
glossary Object { id: 149, … }
id 149
field_name "Field Name 149"
groups [ {…} ]
0 Object { id: 59, name: "Group 59", … }
I tried:
editor.where( function () {
this
.orWhere( function () {
for ( let i=0; i < getData.selectGroupID.length; i++ ){
this.orWhere( 'groups.id', '( SELECT DISTINCT group_id FROM glossary_groups )', 'IN', false);
}
})
});
But I'm getting this error:
TypeError: The operator "( SELECT DISTINCT group_id FROM glossary_groups )" is not permitted
I also tried:
editor.where( function () {
this
.orWhere( function () {
for ( let i=0; i < getData.selectGroupID.length; i++ ){
//this.orWhere( 'groups.id', getData.selectGroupID[i] );
//this.orWhere( 'groups.id', 'SELECT DISTINCT group_id FROM glossary_groups', '=', getData.selectGroupID[i] );
//this.orWhere( 'glossary.id', '=', 51 );
//this.orWhere( 'glossary.id', '( SELECT DISTINCT group_id FROM glossary_groups )', 'IN', [[59, 60]] );
//this.orWhere( 'glossary.id', '( SELECT DISTINCT glossary_id FROM glossary_groups )', 'IN', false);
}
})
});
On this post they suggest a raw select distinct:
https://datatables.net/forums/discussion/comment/178893#Comment_178893
//check whether the respective user has any permission
->where( function($q) {
$q ->where( 'users.id',
'( SELECT DISTINCT user_id
FROM user_permission
)', 'IN', false);
and I think this is a https://editor.datatables.net/manual/php/conditions#Sub-selects
But how to perform the same logic with node.js? https://editor.datatables.net/manual/nodejs/conditions