Join queries

Join queries can be performed on relations defined in the semantics module. That includes the property types:

  • ParentNodeRelationPropertyClass
  • ChildNodeRelationPropertyClass
  • ParentsNodeRelationsPropertyClass
  • ChildrenNodeRelationsPropertyClass

(The NodeParentPropertyClass property type does not support join queries.)

The join queries are defined using an alias class that refers to the relation. Here is an example:

var q = WAFContext.Session.CreateQuery();
var parent = new AqlAliasArticleBase();
var child = new AqlAliasArticleBase();
var join = new AqlAliasRelHierarchical(parent, child);
q.From(join);
var rParent = q.Select(parent.Name);
var rChild = q.Select(child.Name);
var rs = q.Execute();

 

This query starts by defining two references the article class, one for the parents, and one for the children. Once we have a reference to the two classes we want to join we create a reference to the relation. In the constructor of the join we specify the left and right part of the join. The example joins articles over the hierarchical relation used by the parent and children property of all objects that inherit from “HierarchicalContent”. Even though the relation can contain content objects that does not inherit from ArticleBase, all objects in the result will be filtered since the alias classes are ArticleBase.

You can combine multiple joins in one query by chaining the joins:

var q = WAFContext.Session.CreateQuery();
var parent = new AqlAliasArticleBase();
var child = new AqlAliasArticleBase();
var childOfChild = new AqlAliasArticleBase();
var join1 = new AqlAliasRelHierarchical(parent, child);
var join2 = new AqlAliasRelHierarchical(join1, childOfChild, child);
q.From(join2);
var rParent = q.Select(parent.Name);
var rChild = q.Select(child.Name);
var rChildOfChild = q.Select(childOfchild.Name);
var rs = q.Execute();

 

In this example “join2” continues on “join1” using the “child” as the parent in the second join. The join is by default an inner join so this query will return all articles that are joined in three levels.