Skip to content
Snippets Groups Projects
Commit 282249c9 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Add composite foreign key habilities to RQF

Now you can join tables with composite foreign/primary keys using RQF. In the
join attribute just use an array of columns that need to be used in the join
parent 8aa5528f
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!34Db simcaq dev2
Pipeline #
...@@ -201,7 +201,19 @@ class ReqQueryFields { ...@@ -201,7 +201,19 @@ class ReqQueryFields {
let foreignTable = ''; let foreignTable = '';
if(value.join.foreignTable) foreignTable = value.join.foreignTable+'.'; if(value.join.foreignTable) foreignTable = value.join.foreignTable+'.';
// Fazemos o join // Fazemos o join
req.sql.join(value.table, null, foreignTable+value.join.foreign+'='+value.table+'.'+value.join.primary); let onClause = '';
if(Array.isArray(value.join.primary)) {
// Se é um array, montamos a cláusula ON com mais de uma coluna
value.join.primary.forEach((column, index, arr) => {
onClause += foreignTable+value.join.foreign[index]+'='+value.table+'.'+column;
if(index < arr.length-1) {
onClause+=' AND ';
}
});
} else {
onClause = foreignTable+value.join.foreign+'='+value.table+'.'+value.join.primary;
}
req.sql.join(value.table, null, onClause);
// Marcamos o join como feito para não ter problemas // Marcamos o join como feito para não ter problemas
hasJoined[value.name] = true; hasJoined[value.name] = true;
// values[k].hasJoined = true; // values[k].hasJoined = true;
......
...@@ -188,8 +188,8 @@ rqf.addField({ ...@@ -188,8 +188,8 @@ rqf.addField({
field: 'id' field: 'id'
}, },
join: { join: {
primary: 'id', primary: ['id', 'ano_censo'],
foreign: 'escola_id', foreign: ['escola_id', 'ano_censo'],
foreignTable: 'matricula' foreignTable: 'matricula'
} }
}).addValue({ }).addValue({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment