Is there a JourneyApps DB query equivalent to SQL join?

I'm trying to query a table that has a belongs to attribute. I'm curious what the pattern would be to have one query to connect multiple tables?

There is a standard query method in JourneyApps which allows this called .include The documentation can be found Here

Currently, if you wanted to look up a belongs-to relationship, you could do so without using .include by using the following code where person belongs-to city:

var people = DB.person.all().toArray();
people.forEach(function(person) {
console.log('city', person.city());
});

Using include, the query can be simplified as follows:

var people = DB.person.all().include('city').toArray();
people.forEach(function(person) {
console.log('city', person.city());
});

You can also use .map to perform a function on an array in order to return a new array, e.g.:

var array1 = [1,4,9,16];
var mappedArray = array1.map(function(number){
return (number * 2);
});
console.log(mappedArray);
//  mappedArray = [2,8,18,32];
2 Likes

Thanks @JasonBordelon. For some reason I just skipped over this in documentation. But the example is extremely helpful!

@JasonBordelon Is it possible to utilize orderBy() with the included table? For instance DB.person.all().include('city').orderBy('_city name_').toArray()