Struggling with creating a two-level JOIN in SQLike, currently stuck at the one level JOIN.
The source tables are JSONs:
var placesJSON=[{"id":"173","name":"England","type":"SUBCTRY"},{"id":"580","name":"Great Britain","type":"CTRY"},{"id":"821","name":"Southern England","type":"REG"},{"id":"822","name":"Northern England","type":"REG"},{"id":"831","name":"Southwest England","type":"REG"},{"id":"832","name":"Southeast England","type":"REG"},{"id":"833","name":"Western Midlands","type":"REG"},{"id":"834","name":"Eastern Midlands","type":"REG"},{"id":"889","name":"Eastern England","type":"REG"},{"id":"937","name":"Central Southern England","type":"REG"}];
var relationsJSON=[{"son":"173","father":"580"},{"son":"821","father":"173"},{"son":"822","father":"173"},{"son":"831","father":"173"},{"son":"832","father":"173"},{"son":"833","father":"173"},{"son":"834","father":"173"},{"son":"889","father":"173"},{"son":"937","father":"173"}];
This is the MySQL equivalent query:
SELECT DISTINCT p.id, p.name, p.type, r.son, r.father, f.name
FROM places p
JOIN places_relations r ON p.id=r.son
JOIN places f ON f.id=r.father
The first JOIN works well:
SQLike.q({
SelectDistinct: ['p_id', 'p_name', 'r_son' ,'p_type', 'r_father'],
From: {p:placesJSON},
Join: {r:relationsJSON},
On: function(){return this.p.id==this.r.son}
})
When attempting to add the second JOIN, no results are returned. The attempted syntax:
SQLike.q({
SelectDistinct: ['p_id', 'p_name', 'r_son' ,'p_type', 'r_father', 'f_name'],
From: {p:placesJSON},
Join: {r:relationsJSON},
On: function(){return this.p.id==this.r.son},
Join: {f:placesJSON},
On: function(){return this.f.id==this.r.father}
Any suggestions on how to solve this issue?